Lab 5: Creating a Foundational Module

本文介绍如何使用WebClient软件工厂创建基础模块,并实现简单的导航服务。通过实际操作,展示如何配置模块依赖、注册全局服务及更新控制器以实现页面流程。

Lab 5: Creating a Foundational Module

Purpose

Estimated time to complete this lab: 30 minutes

In this exercise, you will learn how to use the Web Client Software Factory to create a foundational module. A foundational module does not contain Web pages; it also should not contain anything related to the user interface (UI). The primary purpose of a foundational module is to provide services to the other modules in the application. For example, a foundational module can contain code that provides instrumentation, such as logging.

In the following procedures, you will create a foundational module and implement a simple service that is responsible for providing navigation between views. You will update the EFT module to consume the navigation service to provide the “Process Transfers” page flow, as shown in Figure 1.

Figure 1
Process Transfers page flow

Preparation

Before proceeding with this lab, you must install and configure the prerequisite software. For more information, see Web Client Software Factory Hands-On Labs.

Open the solution for the previous lab (either the one that you created or the end solution for that lab.) If you use the provided end solution, you must enable the guidance package for that solution.

To enable the Web Client Development guidance package with the Guidance Package Manager

1.       Using Visual Studio, open the solution.

2.       On the Tools menu, click Guidance Package Manager.

3.       In the Guidance Package Manager dialog box, click Enable / Disable Packages.

4.       In the Enable and Disable Packages dialog box, select the Web Client Development check box.

5.       Click OK.

Procedures

This lab includes the following tasks:

·         Task 1: Use the Guidance Package to Add a New Foundational Module

·         Task 2: Review the Foundational Module Configuration Section

·         Task 3: Create a Navigation Service Implementation

·         Task 4: Register the Navigation Service as a Global Service

·         Task 5: Specify That the EFT Module Depends on the Navigation Module

·         Task 6: Add a View to the EFT Module to Review the Transfers

·         Task 7: Add a Summary View to the EFT

·         Task 8: Add a Submit Button to the NewTransferView View

·         Task 9: Update the EFT Module Controller to Use the INavigationService

The next sections describe each of these tasks.

Task 1: Use the Guidance Package to Add a New Foundational Module

The Web Client Development guidance package included in the Web Client Software Factory includes the Add Foundational Module recipe, which automates the creation of foundational modules. In this task, you will use the recipe to add a foundational module to your application.

To use the guidance package to add a new foundational module

1.       In the Modules solution folder, create a subfolder named Navigation.

2.       In Solution Explorer, right-click the Navigation solution folder, point to Web Client Factory, and then click Add Foundational Module (C#), as shown in Figure 2. This opens the Add New Project dialog box.

Figure 2
Process to open Add New Project dialog box

3.       In the Name box of the Add New Project dialog box, type Navigation, and then type % SOLUTION_DIR% /Modules/Navigation in the Location box, as shown in Figure 3. (If you use the Browse button to set the location, you will have to create the Navigation folder).

Figure 3
Add New Project dialog box

4.       Click OK to create the project and launch the recipe wizard, which is illustrated in Figure 4.

Figure 4
Add Foundational Model recipe wizard

5.       Select the Create project for unit tests check box, and then click Finish to create the module.

Task 2: Review the Foundational Module Configuration Section

All modules have an associated configuration section in a Web.config file. The Composite Web Application Block uses this configuration to identify the module assembly and, in case of business modules, to identify the location of the module’s Web pages. When your Web client application starts, the Composite Web Application Block locates the configuration section for each module and uses this information to load module assemblies. You can specify the module configuration in the Web.config file for the Web site, or, in the case of business modules, you can create a module-specific Web.config file in the module's Web site folder. In this task, you will review the configuration section created by the Add Foundational Module recipe for the Navigation module.

To review the foundational module configuration section

1.       Open the root Web.config file of the DevelopmentWebsite site.

2.       Locate the compositeWeb configuration section. This section contains configuration information for the modules of your application.

3.       Locate the configuration section for the Navigation module.

<module name="Navigation" assemblyName="Navigation" />

Note: This configuration section specifies the module name and the module assembly. Business modules also specify a virtualPath attribute, which defines the location of the module Web pages. Inside a module element, you can also specify dependencies on other modules. For more information, see ”Modules” in Web Client Software Factory Help.

Task 3: Create a Navigation Service Implementation

In this task, you will create a simple service that will provide navigation logic between pages.

To create a navigation service implementation

1.       Create a new interface named INavigationService in the Services folder of the Navigation module. The interface will only contain a method named Navigate that will perform a page transition. Use the following code as the interface definition.

public interface INavigationService

{

    void Navigate(string view);

}

2.       In the Navigation project, add a reference to the System.Web assembly. To do this, right-click the Navigation project node in Solution Explorer, and then click Add Reference. On the .NET tab, select System.Web, and then click OK.

3.       In the Services folder, create a class named RedirectNavigationService. Implement the INavigationService interface you defined in the previous step, and then use the ASP.NET Response.Redirect method to provide navigation, as shown in the following code.

public class RedirectNavigationService : INavigationService

{

    #region INavigationService Members

 

    public void Navigate(string view)

    {

        System.Web.HttpContext.Current.Response.Redirect(view, true);

    }

 

    #endregion

}

Task 4: Register the Navigation Service as a Global Service

To be able to consume the navigation service from any module in your application, you must register it as a global service. Global services are services that can be shared across multiple modules in the solution. In this task, you will register the INavigationService as a global service by implementing the AddGlobalServices method in the module initialization class of the Navigation module.

To register the navigation service as a global service

1.       In the Navigation project, open the file NavigationModuleInitializer.cs. This is the Navigation module’s initialization class.

2.       Add the following using statement to the top of the file. You will use it to reference the navigation service.

using GlobalBank.Navigation.Services;

3.       Locate the AddGlobalServices method. (You use this method to register global services.) Add the following code to the method body to register the navigation service.

globalServices.AddNew<RedirectNavigationService, INavigationService>();

Note: The globalServices object is a collection of services. In this particular case, it is the services collection of the root composition container. You use the AddNew method to have ObjectBuilder create a new instance of the service and add it to the services collection. By adding a service to the services collection of the root composition container, you automatically make it available to all the modules in your application. 

For more information about registering services, see “How to: Register and Use Services” in Web Client Software Factory Help.

Task 5: Specify That the EFT Module Depends on the Navigation Module

You can express module dependencies in the module configuration section. Module dependencies define the order that modules are loaded by the Composite Web Application Block when the application starts. In this task, you will specify that the EFT module depends on the Navigation module. This means the Composite Web Application Block will load the Navigation module before the EFT module, and the INavigationService service (registered by the Navigation module) will be available when the EFT module is loaded.

To specify that the EFT module depends on the Navigation module

1.       In the EFT folder of the DevelopmentWebsite site, open the Web.config file.

2.       Add the bold line of the following tag inside the dependencies tag.

<module name="EFT" assemblyName="EFT" virtualPath="~/EFT">

  <dependencies>

    <dependency module="Shell" />

    <dependency module="Navigation" />

  </dependencies>

</module>

Note: By default, business modules created with the Add Business Module recipe have a dependency on the Shell module. This is because business modules consume the ISiteMapBuilderService (to build the module’s site map), which is registered by the Shell module.

Task 6: Add a View to the EFT Module to Review the Transfers

In this task, you will create a view that will let users review the transfers before submitting them. You will use the INavigationService to navigate from the NewTransfersView view to this view.

To add a view to the EFT module to review the transfers

1.       In the EFT folder for the Web site, create a new view named ReviewTransfersView. To do this, right-click the EFT folder in the DevelopmentWebsite site, point to Web Client Factory, and then click Add View (with presenter) (C#). In the Name box of the recipe wizard, type ReviewTransfersView, and then click Finish to create the view, which illustrated in Figure 5.

Figure 5
ReviewTransfersView view

2.       Add the following using statement to the IReviewTransfersView interface file.

using GlobalBank.EFT.BusinessEntities;

3.       Add the following property to the IReviewTransfersView interface definition. This property will be called by the presenter to set the transfers to display in the view.

IList<Transfer> Transfers { set; }

4.       Open the Design view for the Web page ReviewTransfersView.aspx, and then drag an ObjectContainerDataSource control from the Toolbox. You will use this control to bind the list of transfers with a GridView control.

 

Note: To add the ObjectContainerDataSource control to the Toolbox, right-click the Data tab in the Toolbox, and then click Choose Items. On the .NET Framework Components tab, click Browse, select the Microsoft.Practices.Web.UI.WebControls.dll assembly (located in %WCSF_INSTALL_DIR%/Microsoft Practices Library/Microsoft.Practices.Web.UI.WebControls.dll), and then click Open. In the list of components, click ObjectContainerDataSource, and then click OK.

5.       On the Smart Tag menu, click Configure Data Source. The Configure Data Source dialog box appears.

6.       In the Configure Data Source dialog box, select the data object type GlobalBank.EFT.BusinessEntities.Transfer, and then click OK.

7.       In the Properties window of the control, set the ID of the control to TransfersDataSource.

8.       Add a GridView control below the page title.

9.       Bind the GridView control to the TransfersDataSource control. To do this, set the DataSourceID property to TransfersDataSource.

10.   Click the Edit Fields link on the Smart Tag. (If the GridView Tasks shortcut menu does not appear, right-click the GridView control, and then click Show Smart Tag.)

11.   Under Selected fields in the Fields dialog box, delete the Status field and the Id field.

12.   Click OK to close the Fields dialog box.

13.   Add two buttons labeled Revise and Process to the page. Set the ID property to ReviseButton and ProcessButton, respectively.

14.   Double-click ReviseButton to have Visual Studio create event handlers for the click event. Repeat this step with the ProcessButton.

15.   Implement the handlers for the click event of both buttons. In the handlers, forward the events to the presenter, as shown in the following code.

protected void ReviseButton_Click(object sender, EventArgs e)

{

    _presenter.OnReviseTransfers();

}

protected void ProcessButton_Click(object sender, EventArgs e)

{

    _presenter.OnProcessTransfers();

}

16.   Open the ReviewTransfersView.aspx.cs file, and then add the following using statements.

using System.Collections.Generic;

using GlobalBank.EFT.BusinessEntities;

17.   Paste the following code inside the class body to implement the Transfers property. This property will set the transfers in the TransfersDataSource control.

public System.Collections.Generic.IList<Transfer> Transfers

{

    set { TransfersDataSource.DataSource = value; }

}

18.   Modify the ReviewTransfersViewPresenter’s constructor method to make ObjectBuilder inject a new instance of the EFTController class in the constructor. To do this, uncomment the constructor generated by the Add View (with presenter) recipe.

private EFTController _controller;

 

public ReviewTransfersViewPresenter([CreateNew] EFTController controller)

{

    _controller = controller;

}

19.   Implement the OnReviseTransfers method and the OnProcessTransfers method in the presenter. In these methods, call the EFTController methods to revise and process the transfers, respectively. You will implement the EFTController methods in a subsequent task.

public void OnReviseTransfers()

{

    _controller.ReviseTransfers();

}

 

public void OnProcessTransfers()

{

    _controller.ProcessTransfers();

}

20.   When the view loads, it must show the transfers the user entered in the NewTransfersView view. To do this, implement the OnViewLoaded method with the following code.

public override void OnViewLoaded()

{

    this.View.Transfers = _controller.GetTransfers();

}

21.   Add a stub implementation of the Transfers property in the MockReviewTransfersView test class located in EFT.Tests/ReviewTransfersViewPresenterFixture.cs. (The purpose of the stub is to allow the solution to successfully compile.)

public IList<GlobalBank.EFT.BusinessEntities.Transfer> Transfers

{

    set { throw new Exception("The property is not implemented.");}  }

Note: Creating unit tests is out of the scope of the current lab. For information about how to unit test a presenter, see “Lab 3: Adding Views and Unit Testing” and ”How to: Unit Test a Presenter” in Web Client Software Factory Help.

Task 7: Add a Summary View to the EFT

In this task, you will create a view that will show a summary when the user completes the page flow.

To add a summary view to the EFT

1.       Create a new view named SummaryView in the EFT folder of the Web site. To do this in Solution Explorer, right-click the EFT folder in the DevelopmentWebsite site, point to Web Client Factory, and then click Add View (with Presenter) (C#). In the Name box of the recipe wizard, type SummaryView, and then click Finish to create the view.

2.       In the view, add a legend below the header saying that the transfers have been processed, as shown in Figure 6.

Figure 6
SummaryView view

Task 8: Add a Submit Button to the NewTransferView View

In this task, you will add a submit button to the NewTransferView view. When the user clicks the button, the browser will be redirected to the ReviewTransfersView view so users can review the transfers before actually submitting them.

To add a Submit button to the NewTransferView view

1.       Open the Designer for the EFT/NewTransferView.aspx page and add a button below the GridView control.

2.       Set the button’s Text property to Submit Transfers.

3.       Set the ID property to SubmitTransfersButton.

4.       Double-click the button to have Visual Studio generate an event handler for the click event. Add the bold line in the following code to forward the event to the presenter.

protected void SubmitTransfersButton_Click(object sender, EventArgs e)

{

    _presenter.OnSubmitTransfers();

}

5.       Implement the OnSubmitTransfers method in the presenter. To do this, open the NewTransferViewPresenter.cs file located in the EFT module, and then add the following code. In the next task, you will implement the SubmitTransfers method in the controller.

public void OnSubmitTransfers()

{

    _controller.SubmitTransfers();

}

Task 9: Update the EFT Module Controller to Use the INavigationService

In this task, you will update the EFT module controller to use the INavigationService to perform transitions between views.

To update the EFT module controller to use the INavigationService

1.       In the EFT project, add a project reference to the Navigation project. To do this, right-click the EFT project, and then click Add Reference. On the Projects tab, select the Navigation project, and then click OK.

Note: You add a reference to the Navigation module because the EFT module requires the INavigationService service. This creates a dependency on the Navigation module. If you want to decouple the modules, you could create a separate project for the service interfaces and have the EFT module have a reference to it instead of having a direct reference to the Navigation project. If you do this, you do not have to rebuild the EFT project when you change the service implementation, as long as the interface remains unchanged.

2.       Open the file EFTController.cs located in the root of the EFT project.

3.       Add the following using statement. You will use it to refer to the navigation service.

using GlobalBank.Navigation.Services;

4.       Add the following member variable declaration to the class. This variable will hold a reference to an instance of the INavigationService.

private INavigationService _navigationService;

To get a reference to a valid instance of the INavigationService, you will use the Dependency Injection pattern. ObjectBuilder will inject a valid instance when creating the EFTController class.

 

Note: For more information about the Dependency Injection pattern, see ”Dependency Injection” in Web Client Software Factory Help.

 

5.       Add a second parameter to the constructor to obtain a reference to an instance of the INavigationService service. Store it in the variable you defined in the previous step, as shown in the bold lines of the following code.

[InjectionConstructor]

public EFTController(

     [ServiceDependency] ITransferService transferService,

     [ServiceDependency] INavigationService navigationService)

{

     _transferService = transferService;

     _navigationService = navigationService;

}

6.       Change the CreateNewTransfers method of the EFT module controller so that it uses the INavigationService to navigate to the NewTransferView view.

public virtual void CreateNewTransfers()

{

    _navigationService.Navigate("NewTransferView.aspx");

}

7.       Implement the ReviseTransfers method. This method should use the INavigationService to redirect the browser back to the NewTransferView view so the user can revise the transfers, as shown in the following code.

public virtual void ReviseTransfers()

{

    _navigationService.Navigate("NewTransferView.aspx");

}

8.       Implement the SubmitTransfers method. This method should use the INavigationService to redirect the browser to the ReviewTransfersView view, as shown in the following code.

public virtual void SubmitTransfers()

{

    _navigationService.Navigate("ReviewTransfersView.aspx");

}

9.       Implement the ProcessTransfers method. This method is called when the user confirms the transfers; therefore, it should process the transfers, remove the transfers from the user’s session, and redirect the browser to the SummaryView view. You can use the following code to implement the method.

public virtual void ProcessTransfers()

{

    _transferService.ProcessTransfers(Transfers.ToArray());

    Transfers.Clear();

    _navigationService.Navigate("SummaryView.aspx");

}

Verification

In this section, you will validate that you implemented the Process Transfers page flow correctly.

To validate that you implemented the Process Transfers page flow correctly

1.       Comment the test method GetLastTransferDateConsumesITransferService located in the EFT.Tests/EFTModuleControllerFixture.cs file (it is no longer valid and would raise compilation errors).

2.       Build and run the application.

3.       Click the Transfers site map node to start the Process Transfers page flow.

4.       Complete the page flow.

5.       After you process a transfer, click the Transfers site map node again. You should see the date and time of the transfer you have just added, as shown in Figure 7.

Figure 7
Last Transfer page

 

内容概要:本文档是一份关于“超声谐波成像中幅超声谐波成像中幅度调制聚焦超声引起的全场位移和应变的分析模型(Matlab代码实现)度调制聚焦超声引起的全场位移和应变的分析模型”的Matlab代码实现研究资料,重点构建了一个用于分析在超声谐波成像过程中,由幅度调制聚焦超声所引发的生物组织全场位移与应变的数学模型。该模型通过Matlab仿真手段实现了对声场激励下组织力学响应的精确计算与可视化,有助于深入理解超声激励与组织变形之间的物理机制,提升超声弹性成像的精度与可靠性。文档还附带多个相关科研领域的Matlab/Simulink代码实例,涵盖无人机控制、路径规划、电力系统仿真、信号处理、机器学习等多个方向,展示了强大的技术支撑与应用拓展能力。; 适合人群:具备Matlab编程基础,从事医学超声成像、生物力学建模、信号与图像处理等相关领域研究的研究生、科研人员及工程技术人员。; 使用场景及目标:①用于超声弹性成像中组织力学响应的仿真与分析;②为开发新型超声诊断技术提供理论模型与算法支持;③作为多物理场耦合仿真的教学与研究案例,促进跨学科技术融合。; 阅读建议:建议读者结合Matlab代码逐行理解模型实现细节,重点关注声场建模、组织力学方程求解及位移应变后处理部分。同时可参考文档中提供的其他仿真案例,拓宽研究思路,提升综合科研能力。
标题基于SpringBoot的高校餐饮档口管理系统设计与实现AI更换标题第1章引言介绍高校餐饮档口管理系统的研究背景、意义、国内外现状及论文方法与创新点。1.1研究背景与意义阐述高校餐饮档口管理现状及系统开发的重要性。1.2国内外研究现状分析国内外高校餐饮管理系统的研究与应用进展。1.3研究方法及创新点概述本文采用的研究方法及系统设计的创新之处。第2章相关理论总结与高校餐饮档口管理系统相关的现有理论。2.1SpringBoot框架理论阐述SpringBoot框架的原理、优势及其在Web开发中的应用。2.2数据库设计理论介绍数据库设计的基本原则、方法和步骤。2.3系统安全理论讨论系统安全设计的重要性及常见安全措施。第3章系统需求分析对高校餐饮档口管理系统的功能需求、性能需求等进行详细分析。3.1功能需求分析列举系统需实现的主要功能,如档口管理、订单处理等。3.2性能需求分析分析系统对响应时间、并发处理能力等性能指标的要求。3.3非功能需求分析阐述系统对易用性、可维护性等非功能方面的需求。第4章系统设计详细描述高校餐饮档口管理系统的设计过程。4.1系统架构设计给出系统的整体架构,包括前端、后端和数据库的设计。4.2模块设计详细介绍各个功能模块的设计,如用户管理、档口信息管理等。4.3数据库设计阐述数据库表结构的设计、数据关系及索引优化等。第5章系统实现与测试介绍高校餐饮档口管理系统的实现过程及测试方法。5.1系统实现系统各模块的具体实现过程,包括代码编写和调试。5.2系统测试方法介绍系统测试的方法、测试用例设计及测试环境搭建。5.3系统测试结果与分析从功能、性能等方面对系统测试结果进行详细分析。第6章结论与展望总结本文的研究成果,并展望未来的研究方向。6.1研究结论概括高校餐饮档口管理系统的设计与实现成果。6.2展望指出系统存在的不足及未来改进和扩展的方向。
【ACDC微电网的能源管理策略】微电网仿真模型包括光伏发电机、燃料电池系统、超级电容器和直流侧的电池,包括电压源变换器(VSC),用于将微电网的直流侧与交流侧相连接Simulink仿真实现内容概要:本文介绍了一个基于Simulink的AC/DC微电网仿真模型,该模型集成了光伏发电机、燃料电池系统、超级电容器和直流侧电池等多种分布式能源和储能单元,并通过电压源变换器(VSC)实现微电网直流侧与交流侧的连接。文档重点阐述了微电网的能源管理策略,旨在协调不同能源之间的功率分配,提升系统运行效率与稳定性。此外,文中还提到了多种相关的科研方向和技术实现,如风光出力场景生成、微电网动态经济调度、多目标优化算法等,展示了其在新能源系统仿真与优化领域的综合性应用。 适合人群:具备电力系统、新能源技术或自动化控制等相关背景的科研人员、研究生及工程技术人员,熟悉MATLAB/Simulink仿真环境者更佳。 使用场景及目标:①用于教学与科研中微电网系统建模与仿真;②研究多能源协调控制与能量管理策略;③开发和验证优化算法在微电网调度中的应用;④为实际微电网项目提供仿真验证平台。 其他说明:该资源不仅提供了完整的Simulink仿真模型,还结合多种优化算法和控制策略,具有较强的可扩展性和复用性,建议使用者结合具体研究需求进行参数调整和功能拓展。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值