20110610 DiscuzNT代码研究(1)

20110610 DiscuzNT代码研究(1)

1. 源代码下载

http://nt.discuz.net/showtopic-140676.html

650) this.width=650;” title=”clip_image002″ style=”border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px; border-top-: ” height=”269″ alt=”clip_image002″ width=”553″ border=”0″ src=”http://cdn.verydemo.com/upload/2013_04_13/13658670390780.jpg” />

2. 用VS2010打开项目

650) this.width=650;” title=”clip_image004″ style=”border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px; border-top-: ” height=”334″ alt=”clip_image004″ width=”553″ border=”0″ src=”http://cdn.verydemo.com/upload/2013_04_13/13658670392491.jpg” />

3. 项目结构

650) this.width=650;” title=”clip_image006″ style=”border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px; border-top-: ” height=”266″ alt=”clip_image006″ width=”493″ border=”0″ src=”http://cdn.verydemo.com/upload/2013_04_13/13658670394062.gif” />

4. Discuz.Web 4.1. 文件夹结构

本项目是网站最终的项目,对比网站发布的文件夹

650) this.width=650;” title=”clip_image008″ style=”border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px; border-top-: ” height=”456″ alt=”clip_image008″ width=”493″ border=”0″ src=”http://cdn.verydemo.com/upload/2013_04_13/13658670395623.jpg” />

Discuz.web项目文件夹

650) this.width=650;” title=”clip_image010″ style=”border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px; border-top-: ” height=”564″ alt=”clip_image010″ width=”493″ border=”0″ src=”http://cdn.verydemo.com/upload/2013_04_13/13658670397654.jpg” />

4.2. 关于Bin文件夹

网站所有需要的dll文件都放在Bin文件夹中,总共27个dll文件,其中Discuz自身有22个,刚好对应解决方案的22个项目(其中Discuz.web是网站项目,不生成dll文件),其他dll文件是另外引用的,在“RefDLL”目录下。

650) this.width=650;” title=”clip_image012″ style=”border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px; border-top-: ” height=”462″ alt=”clip_image012″ width=”554″ border=”0″ src=”http://cdn.verydemo.com/upload/2013_04_13/13658670399535.jpg” />

650) this.width=650;” title=”clip_image014″ style=”border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px; border-top-: ” height=”400″ alt=”clip_image014″ width=”274″ border=”0″ src=”http://cdn.verydemo.com/upload/2013_04_13/13658670401096.jpg” />

650) this.width=650;” title=”clip_image016″ style=”border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px; border-top-: ” height=”205″ alt=”clip_image016″ width=”554″ border=”0″ src=”http://cdn.verydemo.com/upload/2013_04_13/13658670402657.jpg” />

5. 如何研究DiscuzNt

1) 研究Discuz.web网站结构

2) 研究dll文件

6. 关于DiscuzNt的运行过程 6.1. 系统安装

一步一步来

我们先按照http://faq.comsenz.com/viewnews-989配置好网站,第一步就是要安装

650) this.width=650;” title=”clip_image018″ style=”border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px; border-top-: ” height=”356″ alt=”clip_image018″ width=”493″ border=”0″ src=”http://cdn.verydemo.com/upload/2013_04_13/13658670407658.jpg” />

这时系统会自动跳转的“Install.aspx”页面

650) this.width=650;” title=”clip_image020″ style=”border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px; border-top-: ” height=”222″ alt=”clip_image020″ width=”553″ border=”0″ src=”http://cdn.verydemo.com/upload/2013_04_13/13658670426099.jpg” />

6.2. 我们从安装开始分析

既然我们知道入口了,我们就先从安装开始分析

7. Discuz.Web 7.1. install 7.1.1. index.aspx 7.1.1.1. 代码分析方法

1) 截图

2) 分析类成员(UML)

3) 分析类成员的实现和作用(深入源代码)

7.1.1.2. 截图

650) this.width=650;” title=”clip_image022″ style=”border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px; border-top-: ” height=”315″ alt=”clip_image022″ width=”553″ border=”0″ src=”http://cdn.verydemo.com/upload/2013_04_13/136586704392110.jpg” />

7.1.1.3. 分析类

从代码的前段,可以看出index.aspx页面没有相应的cs文件,本页面将在被浏览器请求的时候,自动编译一个继承与Page类的页面出来。

为了好分析,我们假设生成的类为index.aspx类

index.aspx的第一行,置顶了本页面的编译语言为C#

<%@ Page Language="C#"%>

index.aspx的C#代码是在<script runat="server">…</script>体现出来。

7.1.1.4. 分析类成员

我们为_Index_Page类画一个UML图,借助“EnterpriseArchitect”工具,非常不错的一个UML建模工具。

650) this.width=650;” title=”clip_image024″ style=”border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px; border-top-: ” height=”154″ alt=”clip_image024″ width=”256″ border=”0″ src=”http://cdn.verydemo.com/upload/2013_04_13/136586704407711.gif” />

从UML类图中可以看出,index.aspx基本上就是一个Page_Load方法,两个字段,这个方法和字段主要做什么作用呢?

7.1.1.5. 分析类成员实现与作用 7.1.1.5.1. Page_Load

如何来分析Page_Load方法,实际上应该是事件方法,这个主要解决什么问题呢?

为了调试某个方法具体作用,有些时候我们需要在方法中添加一些测试方法

650) this.width=650;” title=”clip_image026″ style=”border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px; border-top-: ” height=”134″ alt=”clip_image026″ width=”448″ border=”0″ src=”http://cdn.verydemo.com/upload/2013_04_13/136586704424912.jpg” />

这里,我们添加了一个测试方法“Response.Write(binfolderpath);”,并注释后续的代码,我们的目的是要只要HttpRuntime.BinDirectory返回的是什么样的值,返回结果值如下:

G:\WebServer\DiscuzNt360\source_files\Discuz.Web\bin\

即HttpRuntime.BinDirectory返回的是当前应用程序的 /bin 目录的路径。

7.1.1.6. 知识点

HttpRuntime.BinDirectory ArrayList inexistenceAssemblyList = new ArrayList(); foreach (string assembly in assemblylist) System.IO.File.Exists(binfolderpath + assembly) inexistenceAssemblyList.Add(assembly); msg += "<li>" + assembly + " 中.</li>"; binfolderpath.Replace("bin\\", "") 要铭记在心;每天都是一年中最美好的日子

20110610 DiscuzNT代码研究(1)

相关文章:

你感兴趣的文章:

标签云: