已阅读5页,还剩25页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
Oxite 项目结构分析 Oxite中有6个Project,每个项目各自作为项目架构中的不同的层。下面我们来各自的分析一下这6个项目。我们可以看到这六个项目分别是Oxite,LinqToSqlDataProvider,MVC,Test,OxiteSite,(Oxite.Database 需要安装SQL Server2005)。1. Oxite该项目中包含了Routing的定义,Model和Services服务层的代码,还有Oxite运行时的后台服务类,配置类,同时,在该项目中也定义了数据访问层的接口,但并没有实现。 BackgroundServices 定义了插件的服务类, Extensions 则是各种常用方法的扩展,如IP地址,字符串,以及反射。 Handlers 对HttpHandler进行重载的类。用于对用户请求进行操作。 Infrastructure 本目录中有大量的类,定义了公用方法, Model 这个对OO来说最容易理解,就是对象的定义,在MVC中的M。 Repositoris Oxite的数据访问层接口,使用了Repository模式,和Linq2SQL配合。 Routing 对Routing规则的定义和扩展。,同时也有相应的约束。 Services Oxite的服务层,也就是传统三层架构中的中间服务层。内有服务的接口和具体实现。 Validation 一些常用的验证方法。 2. LinqToSqlDataProviderThis project contains implementations of all the repositories and uses LinqToSql for data access. Currently it doesnt map the database directly to the entity objects but rather to an intermediate set of objects which are then translated into the standard Oxite entites. This is one of the areas were looking at changing in a future release.该项目包据了数据访问层的实现,并用LinqToSql 进行数据库的操作。这个Project中用到了LinqToSql,在项目架构中充当的是数据访问层的实现。3. MVC本项目中包含控制器和视图层的所有代码,用于Controllers到Views的数据通信,并包含用WCF所写的MetaWeblog API用于提供对外服务。 ActionFilters 定义了各种拦截器 Controllers 所有的Controllers都在这个目录下定义。 Extensions MVC框架中的一些方法扩展 BlogML,DateTime,HtmlHelper,HttpCookie Infrastructure 基础类 ModelBinders 作用是将客户端提交的一个数据转化成Model,简单或复杂类型。为Action生成复杂对象参数 Results ? Services 对外的一些服务接口。 Skinning 对主题皮肤操作的一些方法 ViewModels 从Controller中的数据绑定到View时所用到。 ContainerFactory 反射工厂 OxiteApplication.cs 将Globle中的方法转移到这里,将Site项目只负责项目的显示。 4.MVC.Test该项目定义了整个解决方案的测试类,使用X 测试框架。5.Site该项目包含视图,主题和Web.Config文件。并将所有的C#代码放在了Oxite.Mvc项目中。 Site项目中是没有C#代码的,只负责视图的显示。 Content 一些公用的内容,像公用图片,公用脚本,公用资源 Skins 皮肤。里面包含了主题所使用的样式文件和Scripts。 (我个人感觉将一些公用的Scripts放到Content下更合适。) Views 视图Shared 公用的东东。像Error,MasterPage 6. Oxite.Database 数据库项目,方便数据库架构、数据的对比、更新与部署。Ps:由于Database项目需要安装SQL Server2008,而我用的是2008,暂不讲该博客引擎的主要目标:1. 提供撰写博客引擎的一个可重用范例,包括一些基本功能和高级功能(trackbacks, rss, comments, etc)。2. 提供现实场景下的一个非常简单的ASP.NET MVC范例, 便于学习设计和编码MVC架构。 Oxite在Codeplex主页: /oxite源代码下载: /oxite/SourceControl/DownloadSourceCode.aspx?changeSetId=26899 Getting Started with Oxite (摘自codeplex)It is pretty easy to get up and running with Oxite, and well document the steps required right here.System Requirements You can run Oxite on any version of Windows XP, Server 2003, Vista or Server 2008 (32 or 64-bit)There are three pieces of software you need to get started:1.Some version of Visual Studio or Visual Web Developer Express (VWD Express), 2.ASP.NET MVC, and 3.SQL Express 2005 or 2008 If you have Visual Studio or Visual Web Developer Express already installed, then you can skip ahead to Web Platform Installer, otherwise lets go ahead and get VWD Express installed.Install Visual Web Developer Express (VWD Express) Open up the VWD Express download page (right-click and pick open in a new window or tab so you can easily get back to these instructions).In the purple box on the page labeled Visual Web Developer 2008 Express Edition, select the appropriate language and then click on the Download link next to your language choice.A dialog will pop up asking what you want to do with the file vwdexpress.exe (IE7 and Firefox 3.x dialogs shown, you may get a different experience) (IE7) (Firefox)You can run the file directly from IE (after a warning prompt since you are about to run a file from the internet), or save the file to disk and then run it in Firefox. Either way, you should end up running the VWD Express installation. After the usual license agreement step, youll be given a choice of installing SQL Server Express 2008 at this point as well. Go for it, well need it installed to run Oxite anyway.Click next and youll get to see a list of what will be installed, select a location for VWD Express and see the drive space requirements.From here, click Install and it will run through the installation of everything it needs. It may need a restart when it is close to finishing, but it will continue after the restart is completed. When the installation is completely finished, will finish by requesting a restart, which you should do before we move onto the next step.Installing MVC Oxite requires the Beta of ASP.NET MVC, which you can install from the MVC Beta download pageScroll down the page until you see the two files available for download and click on the Download button next to the 1.4 MB .msi fileClick Run and accept the warning in IE, or save it to disk and run it in Firefox. Follow the prompts all the way through the install.It is important that we are doing this step after the installation of VWD Express, as the MVC Beta does some configuration of templates and features that the VWD Express product needs to be able to run MVC projects.Download an Oxite Release or the Oxite source Now it is time to grab a recent release or the most current drop of the source.Release or Source Code checkin: Which one to get? In general you should get the most recent release, as that is a drop of the code that we explicitly chose to package up for people to download. Individual source code checkins are more up-to-date and may contain bug fixes since a release was created, but they may also contain new bugs that just havent been found yet. Downloading from the source code tab also brings down more files that you need, because it brings down a full copy of everything we have checked into this codeplex project. Having said that, you can look down the list of checkins to see if there is any important functionality or changes that have been done since the last release, and then make your own decision about what to download.Regardless of what type of source you choose, you end up pulling down a .zip file full of code, images, binaries, etc. unzip that file into a folder where you have read/write access. To avoid any security access issues, I would stick with a folder that is under your user directory (a folder on the desktop or in your Documents folder for example).Open up the new directory full of files when youve extracted them. If youve downloaded a release, then the top level folders within this new folder will be the various projects that make up the Oxite sample, including /Oxite.Database, /bin, /Oxite.SearchProvider and others. This is the root of the Oxite solution. If youve downloaded a full source code check-in, then the top-level folder will contain /Archive and /Oxite, and the root of the solution will be under the /Oxite folder. Remember the path to that root folder, youll need it in a minute.Open and Run Oxite! Open up Visual Web Developer and do any initial configuration it prompts you to, until you get to the Start Page. Now click the File menu and select Open Project., browse to the root of the solution wherever you extracted it to, and select the Oxite.VWDExpress.sln file.Note: if you are using VWD Express, then use the Oxite.VWDExpress.sln solution. The other solution contains the same basic code, but also has the database and test projects, neither of which are supported by Visual Studio Web Express.Click Open to open the solution. You may be prompted that this is not a trusted location, if you arent opening the code from your own documents folder, and you may be prompted with the source code provider for this solution can not be found. In the first situation, you can click OK to ignore if it is running in a place where you have read/write permission and in the second case you can select Yes to permanently remove the source code control bindings from the project. Once you have the project open, go over to the Solution Explorer on the right hand side of the VWD Express window and find the project named OxiteSite in the list of projects (it should have a globe as an icon), right-click on it and choose Set as Startup.Now you should be all set, so just click on the little green play button on the toolbar of VWD Express or press the F5 key on your keyboard. if everything works as expected, you should have a browser window open in a few moments with the sample datas first post World.Hello() up and visible. 什么是Oxite?时间:2008-12-21 13:26:57来源: 作者:无色 点击:78次 你可能没有听过OXite,但你是否听过 Channel 9 、 Channel 8、 Channel 10、 TechNet Edge、 Mix Online,显然OXite就是这些网站的后台发动机。Mix Online,你就能在Mix首页看到对Oxite的导航。确切的说,Oxite是微软的开源博客内容管理系统,基于ASP .NET MVC架构,正如其团队在Codeplex上的阐述一样,Oxite是为了以下目标而生的: 提供一个Blog范例,除了Blog的基本功能,你还可以了解到Trackback,rss,comment这些基本模块的实现,当然这些东西可以在其他开源项目中了解,但是Oxite至少提供了可以对比借鉴的可能:-) 提供一个现实世界的MVC架构范例。 如果你对MVC和Blog开源项目有十足的兴趣,不妨下载Oxite来了解一下Mix发动机的秘密,下面是如何开始的一点导航: Oxite在Codeplex主页:/oxite Getting Started with Oxite /oxite/Wiki/View.aspx?title=gettingstarted&referringTitle=Home Frequently Asked Questions /oxite/Wiki/View.aspx?title=FAQ&referringTitle=Home CodePub分流:/d/tag.php?n=1&tag=Oxite 还等什么,去下载Oxite来建立自己的博客内容管理系统,顺便学习学习基于MVC架构下的软件设计实现,这是多好的事儿啊。 微软发布了Oxite开源博客平台,但随后强调该平台只针对开发者,无意藉此与WordPress或Movable Type等流行的博客软件展开直接竞争。 微软上周五在网站上公布了Oxite的源代码,并于昨天正式宣布推出该平台。Oxite平台使用微软公共许可(Microsoft Public License)授权方式,这是微软经过开放源代码促进会(OIS)认证的开源许可之一。 微软称,Oxite是一种具有可拓展性的、标准兼容的内容管理系统,旨在支持博客或更大型的网站,能支持广播、引用通告、匿名或验证评论、个人全球统一标识(Gravatar)头像及在任何页面级别输出RSS Feed等功能。用户可在某一站点上创建和编辑一整套页面,并可在页面中定制HTML代码,而且还可在单个站点上创建多个博客。 此外,Oxite还能与ASP.Net MVC、Visual Studio Team Suite和Background Services Architecture等微软开发者软件整合在一起。微软称,开发Oxite平台的最初目的就是向开发者展示ASP.Net MVC的功能。 微软使用Oxite创建了Mix Online网站,并向开发者提供了该站点的源代码以供学习。Mix Online是一个网络社区,其中心内容是微软的Mix网络开发者会议。 微软Oxite项目负责人埃里克波特尔(Erik Porter)称,Oxite并非现有的、已经确立的博客系统的直接竞争者,也无意挑战微软自身的SharePoint工具,后者也带有内容管理系统的功能。他表示,Oxite平台目前的对象仅为开发者,但最终可能适用于全体公众。 波特尔在一个Oxite论坛上写道:“我们对Oxite平台没有任何其他计划,只是希望为开发者提供一个能运行任何站点的范本。也就是说,到目前为止它只是一个社区项目,但如果社区决定要把它带往其他方向,我们也不会加以阻止。”(download :/SourceControl/ListDownloadableCommits.aspx 和一般的web程序一样,Oxite在第一次被访问时将进行初始化操作,即Oxite.OxiteApplication的Application_Start方法。这些操作笼统来说包括两部分,一是设置依赖注入容器并将之存入应用程序状态中(HttpApplicationState),二是通过依赖注入容器中的某些配置加载模块(Oxite分析之Module)。 这两部分的分析入口分别为Application_Start方法中的Applicationcontainer = setupContainer();和load(); 一、设置依赖注入容器 注意力转移至setupContainer方法。该方法直接或间接将大批的对象和类型注册入依赖注入容器。 首先,将几个基础对象注册为单例。 1: parentContainer2: .RegisterInstance(OxiteConfigurationSection)ConfigurationManager.GetSection(oxite)3: .RegisterInstance(new AppSettingsHelper(ConfigurationManager.AppSettings)4: .RegisterInstance(RouteTable.Routes)5: .RegisterInstance(System.Web.Mvc.ModelBinders.Binders)6: .RegisterInstance(ViewEngines.Engines)7: .RegisterInstance(HostingEnvironment.VirtualPathProvider); OxiteConfigurationSectio类,自定义配置节点。其下目前有三个属性:connectionStrings,dataProviders,moduls。可以查看OxiteSite项目下的oxite.confing文件直观的了解其结构。该配置基本上是针对Module的(Oxite分析之Module)。 Oxite几乎将所有东西都放置在一个个模块中,包括最核心的部分。比如设置自定义CollectionerFactiory、自定义ControllerActionInvoker、自定义ViewEngines等在Oxite.Moduls.Core模块中进行。而moduls节点就定义了Oxite系统包括哪些Module; dataProviders定义了各个需要数据访问的Module的数据访问方式的分类(category属性),而在Module的具体定义中可以这个分类注入不同的Repository以达到各个模块可以单独使用不同的数据访问方式设置不同的数据库。 connectionStrings节点结构和站点配置web.config中的系统connectionStrings节点完全相同,这里之所以又进行一次定义,是为了提供给dataProviders使用(dataProviders有个defaultConnectionString属性)。当dataProviders下的元素未定义connectionString时,可以使用dataProviders节点的defaultConnectionString属性对应的connectionStrings节点的元素的connectionString属性(真拗口)。 AppSettingsHelper 类对ConfigurationManager.AppSettings 进行包装, 提供几个读取方法GetInt32、GetString等,用于读取web.config文件中的appSettings节点下的值。其实完全可以将这几个读取方法放入NameValueCollectionExtensions类(Oxite已定义该类)。appSettings节点下,可以定义名称为Oxite.InstanceName的值来指定Oxite实例,该值指导程序在数据库读取Oxite_Site表中的相应配置。还可以定义名称为IsEmail、IsUrl等,值为正则表达式的元素。如果appSettings节点中没有定义这些元素,将会使用程序硬编码中的设置。 RouteTable.Routes,RouteCollection对象。System.Web.Routing中对其定义,稍微熟悉一点ASP.NET MVC应该清楚这是做什么的。 另外ModelBinders.Binders、ViewEngines.Engines 可以参看关于ASP.NET MVC方面的资料。 HostingEnvironment.VirtualPathProvider,HostingEnvironment 类的静态属性,其值是VirtualPathProvider类的对象。个人猜测可能会用在自定义ViewEngine中,不过目前Oxite版本中好像还没地方用。 然后,将web.config中的connectionStrings和自定义节点”oxite”下的connectionStrings注册为单件。 1: foreach (ConnectionStringSettings connectionString in ConfigurationManager.ConnectionStrings)2: parentContainer.RegisterInstance(connectionString.Name, connectionString.ConnectionString);3: 4: foreach (ConnectionStringSettings connectionString in parentContainer.Resolve().ConnectionStrings)5: parentContainer.RegisterInstance(connectionString.Name, connectionString.ConnectionString); 将数据库连接字符串注册为单件,在构造数据库访问对象(或ORM,Linq to Sql、Entity Framework等)将会使用。 接着,两行咋看不太起眼的代码,实际上是进入Oxite核心的入口: 1: parentContainer2: .RegisterInstance(LoadModules, new LoadModules(parentContainer); 创建LoadModules对象,并注册为单例。LoadModules实现了IBootStrapperTask接口。 1: public interface IBootStrapperTask2: 3: void Execute(IDictionary state);4: void Cleanup(IDictionary state);5: 在OxiteApplication的Application_Start调用私有方法load,load调用静态方法 Load。Load方法中,将从依赖注入容器中提取(ResolveAll)所有实现了IBootStrapperTask接口的类的对象,并调用Execute方法(详情查看静态方法Load);在Application_End方法中,类似的将间接执行实现了IBootStrapperTask接口的类的对象的Cleanup方法(详情查看私有方法unload)。当然,目前Oxite版本中只有一个LoadModules对象。 LoadModules类的主要代码: 1: public void Execute(IDictionary state) 2: 3: OxiteConfigurationSection config = container.Resolve(); 4: IModulesLoaded modulesLoaded = this.container.Resolve(); 5: RouteCollection routes = this.container.Resolve(); 6: IFilterRegistry filterRegistry = this.container.Resolve(); 7: ModelBinderDictionary modelBinders = this.container.Resolve(); 8: IBackgroundServiceRegistry backgroundServicesRegistry = this.container.Resolve(); 9: 10: filterRegistry.Clear();11: 12: modelBinders.Clear();13: 14: /todo: (nheskew) get plugin routes registered on load in the right order instead of just clearing the routes before module init15: routes.Clear();16: 17: foreach (OxiteModuleConfigurationElement module in config.Modules)18: 19: IOxiteModule moduleInstance = modulesLoaded.Load(config, module);20: 21: if (moduleInstance != null)22: 23: moduleInstance.RegisterWithContainer();24: moduleInstance.Initialize();25: moduleInstance.RegisterFilters(filterRegistry);26: moduleInstance.RegisterModelBinders(modelBinders);27: 28: this.container.RegisterInstance(modulesLoaded);29: 30: /TODO: (erikpo) Move this into its own BootStrapper and spin up the appropriate executor classes and start them31: IOxiteBackgroundService backgroundServices = moduleInstance as IOxiteBackgroundService;32: 33: if (backgroundServices != null)34: backgroundServices.RegisterBackgroundServices(backgroundServicesRegistry);35: 36: 37: 38: routes.IgnoreRoute(resource.axd/*pathInfo);39: 40: routes.LoadFromModules(modulesLoaded);41: 42: routes.LoadCatchAllFromModules(modulesLoaded);43: 44: container.RegisterInstance(filterRegistry);45: 46: container.RegisterInstance(backgroundServicesRegistry);47: 48: 49: public void Cleanup(IDictionary state)50: 51: container.Resolve().UnloadModules();52: 53: /TODO: (erikpo) Loop through all background services running in the background and stop them54: 在这里我们暂时不去关心IBackgroundServiceRegistry、IFilterRegistry和FilterRegistry的定义,不过通过接口名称可以看出是和后台服务和ActionFilter相关的。 下面简单说说Oxite怎么实现Module(Oxite分析之Module)的插拔功能的。 Oxite中的Module都实现了IOxiteModule接口。当做好一个Module后(源码文件.cs或.vb等),直接复制到OxiteSet的App_Code目录下,或者编译成dll复制到bin目录下并在依赖注入容器中进行注入,然后在oxite配置节点中进行配置即可。轻松实现Module的插拔功能。 IModulesLoaded接口,从字面上看就是”已经加载的Module”,在Oxite中有一个实现:ModulesLoaded类,在依赖注入容器中已经进行了注册:parentContainer.RegisterType() 。该类的Load方法正是实现上述Module插拔功能。 Load方法中将找到的Module实例化,并将对象私有变量List modules中,分别提供泛型和非泛型的GetModules方法供外部读取。当然,这种插拔功能如果完全可以自己另外实现一个:parentContainer.RegisterType()。 然后再看看IOxiteModule接口。 IOxiteModule接口定义了7个方法: 1: public interface IOxiteModule 2: 3: void Initialize(); 4: void Unload(); 5: void RegisterRoutes(RouteCollection routes); 6: void RegisterCatchAllRoutes(RouteCollection routes); 7: void RegisterFilters(IFilterRegistry filterRegistry); 8: void RegisterModelBinders(ModelBinderDictionary modelBinders); 9: void RegisterWithContainer();10: 11: 在LoadModules类的Execute方法中的,查看foreach循环: foreach (XoohooModuleConfigurationElement module in container.Resolve().Modules) 对oxite配置节点获取moduls节点的所有元素进行遍历。 IOxiteModule moduleInstance = modulesLoaded.Load(config, module); ModulesLoaded类实例modulesLoaded的Load方法将Module进行实例化,返回IOxiteModule对象。如果正常返回IOxiteModule对象,就调用如下四个方法: RegisterWithContainer Initialize RegisterFilters RegisterModelBinders 接着: this.container.RegisterInstance(modulesLoaded); 作用是将”已经加载的Module”注册为单例。 这句写在循环里,为什么不写在循环外面? 接下来的几句是关于后台服务的,略去。 跳出循环后: 1: routes.IgnoreRoute(resource.axd/*pathInfo);2: 3: routes.LoadFromModules(modulesLoaded);4: 5: routes.LoadCatchAllFromModules(modulesLoaded);6: 第一句代码比较熟悉,排除axd文件的路由。 第二、三行代码,调用RouteCollection类型的扩展方法LoadFromModules和LoadCatchAllFromModules。这两个方法实际上分别执
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2027届山东省菏泽市单县第五中学高考冲刺模拟数学试题含解析
- 高中二年级历史《欧洲文化的形成》创新教学设计
- 广告营销市场推广管理制度
- 小学语文教资面试教资面试高频考题题库及答案
- 高中历史教资面试高频考题试卷及答案
- 20261030-173542-物业小区雷电专项应急预案
- 20261031-225900-课程顾问竞聘演讲稿
- 20261203-233309-标书制作流程培训(全套)(2027版)
- 高三数学一轮复习“一题一课”:平面向量与三角形四心教学设计
- 高中英语必修第三册Unit 5 Section Ⅱ Reading and Thinking课文习读教学设计
- 2026年单片机原理及应用期末考试题库(含答案)
- 2026 年班组建设工作回顾凝聚团队干事创业力量课件
- 2026年临沧市公安局临翔分局招聘警务辅助人员(30人)笔试备考题库及答案解析
- 2026年中国哲学思想知识竞赛模拟试卷带答案
- Deepseek精通和AI办公提效
- 2026年四川自贡市中考真题【含答案解析】
- 衔接染色体变异补强|补齐结构数目变异断层
- 施工队长解除协议书
- 2026年年终结算通知函(4篇范文)
- 质量安全部月度例会制度
- GB/T 191-2025包装储运图形符号标志
评论
0/150
提交评论