八、开发者工具和指南(一) Developer FAQ
What are the dependencies?
Orchard使用了大量外部库,可以在\lib目录中找到。
What framework versions does Orchard support?
Orchard当前支持.net 4.0,
What types of extensions can I write?
Orchard的模块和主题支持扩展,模块和主题的APIs正在进步,尽管能建立今天的这些扩展,你应该预料到变化 ,可能破坏目前在codebase上建立的扩展,正常的MVC2 Areas也像模块一样被支持。
Where are Modules physically located?
模块在"src\Orchard.Web\Modules"目录中。模块可以包含ASP.NET VIEWS(aspx,ascx,cshtml)和静态内容,不用复制模块从一个项目到另一可能运行的项目。
核心模块是"\src\Orchard.Web\Core"目录中。
What is a Module.txt file?
这个文件是模块的manifest,它被放在模块的根目录,能被Orchard识别并加载。它是YAML格式的文件。下面是一个module.txt的例子:
name: AnotherWiki author: Coder Notaprogrammer website: http://anotherwiki.codeplex.com version: 1.2.3 orchardversion: 1 antiforgery: enabled features: AnotherWiki: Description: My super wiki module for Orchard. Dependencies: Versioning, Search Category: Content types AnotherWiki Editor: Description: A rich editor for wiki contents. Dependencies: TinyMCE, AnotherWiki Category: Input methods AnotherWiki DistributionList: Description: Sends e-mail alerts when wiki contents gets published. Dependencies: AnotherWiki, Email Subscriptions Category: Email AnotherWiki Captcha: Description: Kills spam. Or makes it zombie-like. Dependencies: AnotherWiki, reCaptcha Category: Spam
What is the AdminMenu.cs file?
这个文件实现了Orchard的INavigationProvider接口,它在后端让模块自己加入到管理菜单中,通常是声明你的模块注入到管理菜单的链接,通过链接调用控制器的行为。
What is the Permissions.cs file?
这个文件实现了IPermissionProvider接口,它让模块声明一组权限以及这些权限赋给默认Orchard角色。每次为模块添加一个新权限,你都能使用Orchard 授权APIs检验针对当前用户的权限。也也能在角色管理页面管理自定义哪个角色的权限。
How do I do authorization inside my module against current user/roles?
Orchard自带一个实现IOrchardServices接口的默认服务,在你的构造器中简单的包含IOrchardService,你将得到默认的注入实现,像:
public AdminController(IMyService myService, IOrchardServices orchardServices) { _myService = myService; Services = orchardServices; }
在这点上,services给你关于授权的Authorizer,通知为书面形式通知,ContentManager 关于访问Orchard content manager和TransactionManager,在这点上,检查如果当前用户有某个权限,你应该这样做:
Services.Authorizer.Authorize(Permissions.SomeModulePermission, T("Some operation failed"));
What are Core Modules?
核心模块是Orchard模块,在\src\Orchard.Web\Core目录下,他们也在解决方案中构成Orchard.Core项目,这些模块随Orchard默认安装并一直启用。
Why are Core modules modules?
不同点类似于整体的概念 与 微内核:它在Orchard的高层设计期间是相当明显的,一个就像模块需要的扩展点,一切构成了核心框架。拿通用模块举例,介绍的BodyPart,内容类型的许多类型通用的核心理念,如blog posts或pages。现在我们已经作为Orchard框架DLL的一部分实现了这部分,并且有模块依赖它,但它作为一个模块没有好处,如能hook up handlers,drivers,views,routes等等。这个关系到MVC和areas,同一目录下属于一个area的任何。
Why are Core Modules Core Modules?
现在想要作为模块的核心理念,为什么不连同其它较明显的Orchard模块放进Modules目录,如comments 模块,这是它关于依赖的时候。Orchard中,在Modules中的模块能被禁用、卸载、更新,我们更喜欢自包含的模块,尽可能不依赖其它非核心模块,这是内容类型架构后整个dynamism 的一部分,Payges和Blog posts属于Pages和Blog模块,不引用Comments或Tag模块,但它们可能附加到Pages和Blog模块上,这个行为保证基本的内容类型架构和不直接引用一个或其它模块。核心模块是Orchard框架的一部分,模块可以依赖它们,我们为实际的目的分发它们作为Orchard框架的组成部分。模块能依赖它们并直接访问它们公开的接口。
How do I write and run tests?
Orchard自带了一个Tests解决方案目录,这个承载两种类型的测试:
- Unit Tests: 这些是NUnit测试装置,为模块写一个fixture,在Orchard.Tests.Modules 下简单地创建一个目录,并把你的测试移入。
- Integration Tests: 这些也是NUnit测试,使用SpecFlow生成功能文件,你的集成测试在Orchard.Specs下进行,如果你是新的BDD approach,这有许可示例可以看一下。
注意:这是为Orchard标准源码版的模块写测试,要为你自己的第三方模块写测试,请在你自己的分离的目录进行,我们提供设置一个第三方模块开发环境的指导。
How do I contribute my changes to Orchard?
Orchard是一个社区项目并有一些外部贡献者,要确保patch对Orchard是可接受的,这有几点建议:
- Code Conventions:
- Patch submission process:
How to build a WCF service that exposes Orchard functionality?
要在Orchard中托管WCF服务,它所有的好东西都从IoC来,你必须:
使用新OrchardHost Factory为你的服务 创建一个SVC文件:
<%@ ServiceHost Language="C#" Debug="true" Service="Orchard.Service.Services.IService, Orchard.Service" Factory="Orchard.Wcf.OrchardServiceHostFactory, Orchard.Framework" %>
通常作为IDependency注册服务
using System.ServiceModel; namespace Orchard.Service.Services { [ServiceContract] public interface IService : IDependency { [OperationContract] string GetUserEmail(string username); } }
提供实现,即Service:IService.
What's in App_Data?
AppData用来存储各种数据,AppData中的内容从不被服务,内容被组织成下面这样:
Folder:Dependencies 用来存储动态编译的DLLs并有一个XML文件,dependencies.xml来跟踪每个模块是怎么被编译的(动态地 或不是)
- mappings.bin 是nHibernate mappings的二进制序列化缓存
- Orchard.sdf租户的SQL CE数据库文件
- reports.dat 是旧的日志文件
- Settings.txt 描述每个租户的 low-level设置(database provider, connection string, etc.)
Understanding bug status and triage
Developer Troubleshooting
Record Names: 你实现的ContentPartRecords 不应该有称为keywords的属性 到NHibernate。例如:包含 Identity, Version.