ImageVerifierCode 换一换
格式:DOCX , 页数:22 ,大小:131.21KB ,
资源ID:12885264      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/12885264.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(nopCommerce的源代码结构和架构说明.docx)为本站会员(b****2)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

nopCommerce的源代码结构和架构说明.docx

1、nopCommerce的源代码结构和架构说明nopCommerce的源代码结构和架构编写本文档是为了向程序员说明nopcommerce的解决方案结构,亦是程序员开发nopcommerce的居家必备良书。首先nopcommerce的源代码很容易拿到,它是开源的,所以你可以直接到网上下载。 在你打开VS以后项目和文件夹都会完整列出来,我们建议你在看此文档的同时也打开你的VS来浏览项目和文件。绝大多数的项目,目录和文件都顾名思义,你可以从名字就大概知道是做什么的。比如Nop.Plugin.Payments.PayPalStandard这个我都不用看项目代码就能猜到做什么的。LibrariesNop.

2、CoreNop.Core项目包含nopcommerce的一系列核心类如缓存,事件,辅助类和业务对象(如订单和客户实体类)LibrariesNop.DataNop.Data项目包含一系列的数据访问类和方法以从数据库或其他数据媒介读取和保存数据。它也有助于把数据访问逻辑和你的业务对象分离。 nopcommerce使用Entity Framework (EF) Code-First方法,允许你在nopcommerce代码中定义实体 (所有的核心实体类都在Nop.Core中定义),再让EF生成数据库,这就是为什么会叫Code-First。你接下来可以用LINQ来查询对象,它自己会把查询转换为SQL语句

3、并在数据库里执行。nopcommerce拥有牛B的API让你完全定制持久映射,你可以在这儿和这儿找到Code-First的资料。LibrariesNop.Services此项目包含一系列的核心服务,业务逻辑,验证,如果有数据的话还有数据的计算方法,也就是传说中的业务访问层(BAL)Plugins 文件夹中的那些项目Plugins是VS的解决方案文件夹,硬盘中它是在你解决方案的根目录下。由于项目在编译时的输入路径是”.PresentationNop.WebPluginsGroup.Name”,这样插件的DLL会自动地放到 PresentationNop.WebPlugins文件夹中,用来放置已部

4、署插件。这样也能让插件包含静态文件比如CSS或JS,就不用在项目之间拷贝这些文件了。PresentationNop.AdminNop.Admin是一MVC项目,如果你还从没用过ASP.NET MVC,请猛击这儿有更多信息。可能你已经猜到这是表示层中的管理后台,你可以在 PresentationNop.WebAdministration文件夹中找到它,此项目不能运行。PresentationNop.WebNop.Web也是一MVC项目,前台网店的表示层,这个才是你真正要跑起来的项目,它也是整个应用程序的起始项目。PresentationNop.Web.FrameworkNop.Web.Frame

5、work是一个表示层的类库项目,包括可以让后台和前台使用的一些共用的展示功能。TestNop.Core.TestsNop.Core.Tests是Nop.Core的测试项目TestNop.Data.TestsNop.Data.Tests是Nop.Data的测试项目TestNop.Services.TestsNop.Services.Tests是 Nop.Services的测试项目TestNop.TestsNop.Tests是一个类库,包含其它测试项目中要用的一共有类和辅助方法,此项目不包含任何测试用例扩展现有实体-添加新的属性Updating an existing entity. How to

6、 add a new property.扩展现有实体:如何添加一个新的属性?This tutorial covers how to add a property to the Affiliate entity that ships with the nopCommerce source code.本教程将为代理商实体Affiliate entity添加一个属性,附带nopCom源码。The data model数据模型Entities will have two classes that are used to map records to a table. The first class d

7、efines the properties, fields, and methods consumed by the web application.实体将有两个类用于映射记录表:第一个类定义affiliate的属性、字段和方法。File System Location文件位置: Project RootLibrariesNop.CoreDomainAffiliatesAffiliate.cs Assembly程序集: Nop.Core Solution Location解决方案中的位置: Nop.Core.Domain.Affiliates.Affilate.csThe second cla

8、ss is used to map the properties defined in the class above to their respective SQL columns. The mapping class is also responsible for mapping relationships between different SQL tables.第二个类是将各属性分别映射到对应的SQL列,以及映射不同的SQL表之间的关系。File System Location: Project RootLibrariesNop.DataMappingAffiliatesAffilia

9、teMap.cs Assembly: Nop.Data Solution Location: Nop.Data.Mapping.Affiliates.AffiliateMap.csAdd the following property to the Affiliate class.为Affiliate添加一个属性:/ Instance members must be virtual on data table objects like Affiliate.cs/ Virtual is required by data access frameworks so that these framewo

10、rks/ can implement more complex features like lazy loading.public virtual string AffiliateWebSite get; set; Add the following code to the constructor of the AffiliateMap class.为AffiliateMap添加一个构造函数:/ This code maps a column in the database to the new property we created above/ This creates a nullabl

11、e nvarchar with a length of 255 characters in the/ Affiliate SQL tablethis.Property(m = m.AffiliateWebSite).HasMaxLength(255).IsOptional(); Because Im all about results, at this point I would run the code, re-install the database, and verify that the column was created appropriately.修改数据库,为Affiliate

12、表添加列:AffiliateWebSite,允许为空,navrchar(255)。 重新编译程序The presentation model视图模型The presentation model is used to transport information from a controller to the view (read more at Models have another purpose; defining requirements.表示模型用于传输控制器的信息视图(参考We configured our database to only store 255 characters

13、for the AffiliateWebSite. If we try and save an AffiliateWebSite with 300 characters the application will break (or truncate the text). We want the application to protect users from failures the best we can, and our view models help enforce requirements like string length.我们在数据库中设定AffiliateWebSite长度

14、为255个字符,如果尝试保存300个字符的,程序将中断(或截断文本)。因此需要通过程序强制用户输入不超过255个字符,尽可能地降低出错。File System Location: Project RootPresentationNop.WebAdministrationModelsAffiliatesAffiliateModel.cs Assembly: Nop.Admin Solution Location: Nop.Admin.Models.Affiliates.AffiliateModel.csThe validator class is used to validate the dat

15、a stored inside of the model class (e.g. required fields, max length, and required ranges).验证输入格式File System Location: Project RootPresentationNop.WebAdministrationValidatorsAffiliatesAffiliateValidator.cs Assembly: Nop.Admin Solution Location: Nop.Admin.Validators.Affiliates.AffiliateValidator.csAd

16、d the property to our view model.添加视图模型需要的属性:/ The NopResourceDisplayName provides the key used during localization/ Keep an eye out for more about localization in future blogsNopResourceDisplayName(Admin.Affiliates.Fields.AffiliateWebSite)public string AffiliateWebSite get; set; The requirements co

17、de will be added in the constructor of the validator./I think this code can speak for itselfRuleFor(m = m.AffiliateWebSite).Length(0, 255);The viewFile System Location: Project RootPresentationNop.WebAdministrationViewsAffiliates _CreateOrUpdate.cshtml Assembly: Nop.Admin Solution Location: Nop.Admi

18、n.Views.Affiliates._CreateOrUpdate.cshtmlViews contain the html for displaying model data. Place this html under the active section.在视图中添加一行: Html.NopLabelFor(model = model.AffiliateWebSite): Html.EditorFor(model = model.AffiliateWebSite) Html.ValidationMessageFor(model = model.Active)The controller

19、In this case the controller is responsible for mapping the domain data model to our view model and vice versa. The reason I choose the affiliate model to update is because of the simplicity. I want this to be an introduction to the nopCommerce platform and I would like to keep it as simple as possib

20、le.在这种情况下,控制器负责域数据模型映射到视图模型,反之亦然。这里之所以选择“代理商”模型来更新是因为他比较简单。以便尽可能简单地为大家介绍如何扩展现有实体属性。File System Location: Project RootPresentationNop.WebAdministrationControllerssAffiliateController.cs Assembly: Nop.Admin Solution Location: Nop.Admin.Controllers.AffiliateController.csWere going to make three updates

21、 to the AffiliateController class. Data Model - View Model Create View Model - Data Model Edit View Model - Data ModelNormally I would write tests for the following code and verify that model mapping is working correctly, but Ill skip unit testing to keep it simple.我们将要进行三次更新AffiliateController类。数据模

22、型 - 视图模型创建视图模型 - 数据模型编辑视图模型 - 数据模型通常情况下,我会写下面的代码测试和验证模型的映射正常工作,但我会跳过单元测试,以保持它的简单。In the method PrepareAffiliateModel add the following code below the model.Active = affiliate.Active:找到Private void PrepareAffiliateModel方法,在model.Active = affiliate.Active后中添加代码:/ Data Model - Ceate/Edit View Modelmode

23、l.AffiliateWebSite = affiliate.AffiliateWebSite;In the public ActionResult Create(AffiliateModel model, bool continueEditing) method add the following code below affiliate.Active = model.Active:找到public ActionResult Create(AffiliateModel model, bool continueEditing)方法,在affiliate.Active = model.Activ

24、e后添加代码:/ Create View Model - Data Modelaffiliate.AffiliateWebSite = model.AffiliateWebSite;A similar change is required in public ActionResult Edit(AffiliateModel model, bool continueEditing):最后,在public ActionResult Edit(AffiliateModel model, bool continueEditing)方法中添加以下代码:/ Edit View Model - Data M

25、odelaffiliate.AffiliateWebSite = model.AffiliateWebSite;Troubleshooting Recreate the database. Either your own custom SQL script or use the nopCommerce installer. Stop the development web server between schema changes. Post a detailed comment on our forums.如何编写nopCommerce插件插件(Plug-in,又叫addin、add-in、

26、addon或add-on)是一种电脑程序,通过和应用程序的互动,用来替应用程序增加一些所需要的特定的功能。(Wikipedia)插件用来扩展nopCommerce的功能,nopcommcer有多种类型的插件。比如支付方式中的paypal,税率供应商,配送计算方式(UPS,USP,Fedex),小部件(live chat功能)等等。nopCommerce本身也自带了很多不同的插件。你可以在官网上搜索是否已经有人上传了满足你需要的插件。如果没有,哥这就手把手带你编写一个出来。插件结构,所用文件,所在位置1.你第一件事就是要在解决方案中新建一个“类库”项目。最好的办法是把插件都放在解决方案根目录(不

27、过小心不要和Nop.Web下边的plugins目录搞混了,那儿是放已布置插件的),而且最好把插件也都放在解决方案目录的plugin目录中(关于更多解决方案文件夹的信息,请猛击此处)最好以这种方法来命名:”Nop.Plugin.Group.Name”。Group是你插件的分类(比如支付),Name是你的插件名(比如”AuthorizeNet”),那么Authorize.NET的支付插件就会有这样的名字:Nop.Plugin.Payments.AuthorizeNet。2.一旦建立了插件项目,把输入路径改为”.PresentationNop.WebPluginsGroup.Name”,比如 Aut

28、horize.NET 支付插件就会有这样的输入路径: “.PresentationNop.WebPluginsPayments.AuthorizeNet”。搞定以后,对应的插件DLL就会被拷贝到 PresentationNop.WebPlugins 文件夹,nopCommerce内核会搜索此文件夹。a.在项目菜单,点击属性b.选择生成选项卡c.点击输入路径旁边的浏览按钮选择一个输入目录你要在debug和release模式下都要做此步骤。3.下一步你就要为你的每一个插件建立一个Description.txt,此文件包含描述插件的信息。你可以从其它插件目录中拷出来。比如Authorize.NET支

29、付插件的Description.txt就有如下内容:Group: Payment methodsFriendlyName: Credit CardSystemName: Payments.AuthorizeNetVersion: 1.00SupportedVersions: 2.30Author: nopCommerce teamDisplayOrder: 1FileName: Nop.Plugin.Payments.AuthorizeNet.dll其实所有的信息你都能看懂,不过有一些注意事项。SystemName必须唯一。Version字段是你插件的版本号,你可以将它设置为你喜欢的任何值。S

30、upportedVersions可以包含一个由逗号分隔的(确保nopCommerce当前版本包含在此列表中,否则此插件没戏)支持版本清单。FileName是用这个格式:Nop.Plugin.Group.Name.dll(是你插件的assembly文件名)。要确保此文件的“拷贝到输入目录”属性是“Copy if newer”4.所需的最后一个步骤是创建一个类实现IPlugin接口(Nop.Core.Plugins命名空间)。nopCommerce有BasePlugin类已经实现了一些IPlugin方法,这样你就不用苦逼地再写一遍。nopCommerce还提供一些从IPlugin派生特定的接口。例

31、如,俺们有“IPaymentMethod”接口,用于创建新的付款插件,它包含了一些特定的用于付款的方法如ProcessPayment()或GetAdditionalHandlingFee()。nopCommerce目前有以下特定的插件接口:IExternalAuthenticationMethod. 用来建立外部认证方法如 Facebook, Twitter, OpenID, etc.IWidgetPlugin. 让你可以创建小部件,小部件在你网站的某些地方出现,如左边的Live chat框IExchangeRateProvider. 用于获得货币汇率.IDiscountRequirementRule. 允许你创建新的折扣规则比如”帐单寄到的国家必须是“ISMSP

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1