DNN模块开发指导(2)

Provider Model

    DNN uses the provider model extensively. A provider pattern enables you to abstract out certain functionality. For example in the architectural diagram (see Figure x) you can see how there is a Abstract Data Provider between the Business Components, and the Concrete Data Provider, this enables you to plug in different providers without having to modify or recompile the core code within DNN.

    DNN uses a provider pattern extensively in it’s architecture. We talked about the database provider, but several other features use this pattern as well.

Security and Membership Provider
Text/HTML Provider
Logging Provider
Scheduler
Friendly URLs

    DNN广泛地使用了provider模式。Provider模版能够让你抽象出一定的功能。例如在架构图中可以看到在BLL和实际数据库之间有个抽象的数据provider,这样就可以使你使用不同的provider而不用重新编译DNN。

    As mentioned, provider patterns enable you to abstract out certain functions, but the actual physical providers are then defined in the web.config. For example, in DNN if you open the web.config you will see a section for the providers:

    已经提到了provider模版使你能够抽象一定的功能,但实际应用的provider是在web.config中定义。例如打开web.config可以看到这个部分;

    By reviewing the web.config definition you can see that each provider is defined by a key, and then specific configuration properties are specified in order to define which physical provider to use. For example in the data section you see the following:

    复习web.config的定义会发现,每个provider都由一个关键字定义,特定的设置将指定哪个provier将被使用。例如:

    The defaultProvider is defined as SQLDataProvider, then within the data key you can see the configuration information for the SQLDataProvider:

    缺省定义是SQLDataProvider,里面能看到具体配置。

    You can see within the provider section of the web.config is the actual physical database information. You could have as many providers as you want defined here, and then switch the defaultProvider value to point to a new physical database provider. Of course you would need to have a provider developed and loaded within your bin folder in order for it to be used. In addition to having a provider for DNN, you would also need to have a provider developed for your module that uses the same physical database as DNN.

    可以在web.config区看到真正的数据库信息。你可以无限定义provider,并且设置defaultProvider值来切换不同的数据库。

    你应当将包括bin文件夹的开发好的provider载入,才能在这里使用。你也需要开发一个使用DNN相同数据库的自己的provider。

Quick Tip: Learn More About Provider Patterns

Rob Howard details out the Provider Pattern in a two part series at Microsoft’s MSDN site:

 

Provider Model Design Pattern and Specification, Part 1:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnaspnet/html/asp02182004.asp

 

Provider Design Pattern, Part 2:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnaspnet/html/asp04212004.asp?frame=true

 

Folder Structure

    DotNetNuke strives to logically structure the folders within the application root folder. The following list provides the folders under the root folder that are important to your development efforts, and what they contain.

    DNN在根目录力求逻辑化组织文件夹。

/Admin – Contains interfaces to the various administrative functions within DNN, for example, the scheduler, tab management, search manager, and any interface that is to be secured and accessible by a portal host or admin.
和DNN不同管理功能接入的容器,例如日程,栏目管理,搜索管理,以及其他。

 

/App_GlobalResources – Contains application specific data like time zone information, and application settings.
包含特定的程序例如时区信息,程序设置。

 

/bin – Contains the compiled assemblies of your DNN solution, and supporting assemblies.
包含DNN编译好的程序集,和其他支持的程序集。

 

/Components – Contains core functionality for DNN.
DNN的核心功能。

 

/controls – Contains the various controls for enhancing the user interface of DNN, for example the Text/HTML provider is located within this folder.
包含各种加强DNN用户界面的各种控件,例如tezt/html就在这里。

 

/DesktopModules – Contains all module projects for DNN. This is where you would place your directory for your module project.
包含所有DNN模块项目。这里你可以设置自己的模块项目。

 

/HttpModules – All HTTPModule projects are contained in here, for example, the exception handler, URLRewriter, Scheduler, and others.
包含所有的HTTPModule项目。


/images – Contains any images used by DNN such as icons.
DNN相关图片,图标。

 

/js – Contains any client side scripts in use by DNN, for example the calendar popup control.
DNN客户脚本,例如弹出日期控件。

 

/portals – Contains the default portal folder, and will contain any portal folders for newly created portals. This provides any new child portal with it’s own personal folder for storing files, and portal skins. Portal folders are identified by a unique integer value which matches up with the Portal ID field value in the Portals table in the DNN database.
包含默认门户文件夹,也会包含新建立的门户站点的文件夹。提供了新子站点的自己的文件夹,皮肤等。

文件夹使用一个和DNN数据库中portals表中portal ID对应的数字作为名称。

 

/Providers – Contains the providers for your DNN portal, for example the database providers are located in a sub directory off of this folder.
包含了DNN的providers,例如数据库providers。

/Resources
/Web references – This folder contains references for Web services, currently the exceptions Web service which allows a portal admin to optionally notify the DNN core team about errors being generated by the portal.
包含web服务的引用,目前的异常web服务在站点出错的时候会通知DNN核心团队。

 

Beginning Module Development

Now that we have covered what modules are, and how they interface with DNN, let’s get started developing modules. In the next sections we will cover how to set up a Visual Studio.Net project, and begin development.

 

开始开发模块

    经过前面的学习,我们可以开始开发模块了。在下面的部分我们将了解如何设置VisualStudio.Net项目,然后开始开发模块。

Configuring Your Visual Studio.NET Project

    Some basic assumptions of this guide are that you have a development machine configured with a default DNN installation within a virtual directory. You should also have some basic knowledge of developing ASP.NET applications in Visual Studio.NET. We are going to build off our default installation of DNN and add our module projects to the solution. By adding to the main DNN solution you ensure you are compiling to the DNN bin directory, and enable debugging for your module project.

 

配置你的VS项目

    假定你已经配置好开发环境,安装了默认的DNN。你需要一些使用VS开发asp.net的基础知识。我们将建立DNN的默认安装,并且添加你的模块项目到解决方案。加入方案时确认编译到DNN的bin目录,并能够调试模块项目。

 

Creating the Module Project

    In order to create our module project you should have your DNN solution open, and we’ll need to add a new project to the solution in order to begin.

    There are various methods for creating modules for DNN, but we prefer to configure a separate project for module creation and then compile the assemblies within each module’s own bin folder. The following procedure provides a method for configuring a portal module project in Visual Studio.NET.

 

创建模块项目

    打开DNN解决方案。有多种方式给DNN添加一个模块,但是我们习惯建立单独的项目,然后在模块自己的bin文件夹中编译程序。

    Create a new class project, be sure to use a logical naming structure. For example: CompanyName.ModuleName. By using this format you ensure your module will not conflict with modules developed by other companies or developers.

    创建一个新的类库项目,确认使用一个逻辑化的命名结构。例如:公司名.模块名。使用这种格式命名将确保你的模块不会和其他开发商的模块混淆。

    When creating the new project folder, create a folder off of the DotNetNuke Root\DesktopModules\ directory.

建立新项目目录时,选择DotNetNuke Root\DesktopModules\ directory这里建立。

    Clear any namespace from the project properties. Right click on properties of the project, under general clear the root namespace box.

    在项目属性中清除命名空间。右键项目,在通用/常规中,清除根命名空间。

    Add a reference to the DotNetNuke project in your new module project.

    在你的新项目中添加DNN项目的引用。

    In the BuildSupport project in the \Solutions\DotNetNuke.DesktopModules\BuildSupport\ directory add a reference to your project. By adding the reference to the BuildSupport project will take the references from your solution to be built within the main DotNetNuke bin directory.

    在BuildSupport项目中添加新建项目的引用。这样可以使你的方案被生成到DNN主bin目录中。

 

Figure 8 – Class Project Properties Dialog

    Now that your project has been created we will create some user controls for your module interface. A simple module can be as basic as a view control to display an interface for your user, and then a settings control for specifying unique values that are specific for a module instance.

    现在项目已经建立了,然后为你的模块界面创建一些用户控件。对用户来说一个模块的浏览控件是基本的,然后是设置控件,对模块实例来说有唯一值。

    This is one area of difficulty when developing module projects for DNN. Since we want to be able to see the results of our development within the portal, the method to accomplish this is by using a class project which allows you in Visual Studio.NET to change the compilation path. Since we are working within a class project the ability to create user controls in Visual Studio.NET is limited and only available when you’re in a Web project. As of this writing, this author has included the Quick Tip below to point you to templates that will make the creation of the controls easier. For the purposes of this guide, we will manually create an item and add our code.

    这里是个难点。由于我们想看到在门户开发中的结果,所以使用了类库项目,这样就可以在vs中改变编译路径。由于我们使用的是类库项目所以不能直接添加用户控件,只有使用web项目时才可以。所以可以参考下面的快速提示使用模版来建立用户控件。在这里我们手工添加控件和代码。

    In our example we work with the Survey module that is included in the DNN distribution. This module is located within the /DesktopModules/Survey directory included in the distribution.

    我们的例子是使用DNN中的Survey模块。它在/DesktopModules/Survey目录中。

    You see some controls, as well as some class files within this folder. Initially when starting a project, you will need to create a few user controls for your user to interact with your module, and for your administrators to configure some module instance settings.

    你将看到一些控件和类。开始一个项目的时候,你需要建立几个用户控件和你的模块交互,并且为你的管理员配置一些模块实例设置。

 

Quick Tip: Ease DNN File Creation

    In this guide we cover creating a module project from scratch; you can streamline this development process by using resources available on the Web. These we’re initially targeted at DNN 2.x, but should also work for DNN 3.x. Try using DNN Project Templates available http://dnnjungle.vmasanas.net/Default.aspx?tabid=28 for creating your module projects, and controls.

 

Creating the Data Provider Project

    The Data Provider project is for developing the methods for interfacing with the physical database. In this guide we discuss SQL Server 2000 as our physical database provider, but your actual provider could be particularly any database such as Access, Oracle, or even MySQL. One of the big advantages of the DNN architecture is a provider model pattern, which enables to you to plug in any provider you wish for the physical database provider. We will discuss the provider pattern later in this guide.

 

建立数据provider项目

    provider项目是为了和实际数据库交互而开发的。在这里我们使用Sql Server2000作为我们的provider。但你的provider可以是任意数据库例如Access,Oracle,甚至是MySql。DNN架构的最大特点之一就是provider模块模式,这样可以使用任意物理数据库的provider。稍后我们将讨论provider模式。

    In module development you create a separate project for each physical dataprovider. You do this similar to the way you configured your module project.

    在模块开发中需要为每个物理数据provider开发独立的项目。建立步骤和建立模块项目是 类似的。

    Create a new class project, be sure to use a logical naming structure. For example: CompanyName.ModuleName.SQLDataProvider. Again, this will avoid naming conflicts with other modules, and keeps you within the naming structure of the module that this provider is going to support.

    When creating the new project folder, create a folder off of the DotNetNuke Root\DesktopModules\ModuleName\ directory, call this directory “Providers”, and create a subdirectory for each provider type you will develop, for example:
\DesktopModules\ModuleName\Providers\SQLDataProvider\

    Clear any namespace from the project properties. Right click on properties of the project, under general clear the root namespace box.
Now add project references to the main DotNetNuke and CompanyName.ModuleName projects.
Add a reference to the BuildSupport project as we did in the module setup.

    Once both projects are configured they should look similar to Figure 9.

    完成后如图9所示。

作者: evan2046

转载于:https://www.cnblogs.com/wymwon/articles/1633119.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值