This document was uploaded by user and they confirmed that they have the permission to share
it. If you are author or own the copyright of this book, please report to us by using this DMCA
report form. Report DMCA
Overview
Download & View Cornerstone Training as PDF for free.
Cornerstone Application Framework Training Class 1
1
Table of Contents Cornerstone History.............................................................................................................................................3 Class Setup...........................................................................................................................................................3 Architecture Overview.........................................................................................................................................4 Developing UIs with Cornerstone vs. Classic ASP.NET.....................................................................................5 Project Structure and Conventions......................................................................................................................5 Developing the HelloWorld Solution..................................................................................................................6 Module 1: Creating the Application Solution..................................................................................................7 Module 2: Integrating the ValueMapper........................................................................................................14 Module 3: Adding a Controller Project..........................................................................................................22 Module 4: Form Layout and Handling Page Events......................................................................................27 Module 5: Consuming Web Services.............................................................................................................37 Module 6: Populating a GridView with Web Service Data...........................................................................55 Module 7: HelloWorld Base Page and Using the Cornerstone SearchControl..............................................76 Module 8: Consuming Data from a Database................................................................................................88 Advanced Topics................................................................................................................................................97 Appendix: Coding Standards.............................................................................................................................97 Appendix: ASP.NET Page Lifecycle.................................................................................................................97 Appendix: Level 3 Environment Concerns.......................................................................................................97
2
Cornerstone History The Cornerstone Application Framework is the evolution of an idea that was first put into practice with the SOE initiative. The goal was to create a consistent, effective toolkit that enables rapid application development cycles by allowing the developer to concentrate more on implementing business requirements and less on tweaking the UI. Cornerstone provides all the building blocks necessary to get a standardized Level 3 application up and running in no time. After several years of development and testing, this toolkit has now been made available to a wider audience of Level 3 developers and will continue to live up to it’s initial purpose by enabling developers to react quickly and produce outstanding results in our continually changing business environment.
Class Setup This class is designed to give you hands-on experience with Cornerstone. You will need the following on your development machine: 1. Visual Studio 2005 with Service Pack 1 2. The latest version of the ASP.NET 2.0 AJAX Extensions (http://www.asp.net/ajax/downloads/) 3. Cornerstone template and xsd files installed (your instructor will help if you have not already done this) 4. Remote access enabled (you will use Microsoft Terminal Server Client to connect to your machine)
3
Architecture Overview The controls, modules, and other primary features of Cornerstone are entirely compatible with and may be used by a traditional ASP.NET application, but have been designed with a particular reference architecture in mind. At a high-level this architecture is based on a standard three-tier MVC approach containing presentation, controller, and data access levels.
The Cornerstone reference design dismisses use of the .ASPX page and relies entirely on the codebehind (aspx.cs) and related embedded controls as the presentation tier. This allows for a more consistent control tree and simplifies debugging. Many of the Cornerstone controls are instantiated by using L3ControlFactory, which adheres to the factory pattern and provides consistency. The controller tier acts as a conduit between the presentation tier and the data access tier. It processes and responds to events and routes data accordingly. The flow controller, which guides page flow and manages state and transfer parameters, also resides here. 4
The data access tier encapsulates all web service calls and database interaction. A ServiceFactory is used to instantiate these object based on UDDI endpoints or provides application independence by seamlessly allowing for stubs (mock data) to be used in their place. Enabling or disabling service stubs is simple process involving a web.config change, and can be performed at runtime.
Developing UIs with Cornerstone vs. Classic ASP.NET Developing a UI with Cornerstone differs from building it in the classic ASP.NET fashion in that the 1. VS Designer is not used (although it's been discussed that a future version of Cornerstone web controls could be made to support the VS Designer) 2. Page layout and controls are controlled entirely in the code-behind file 3. There is only one line of text in the .aspx file of the page
Project Structure and Conventions • •
• •
(Insert project diagram here) Summary of naming conventions for Projects Pages Controls Classes Namespaces Summary of Coding standards Summary of File location
5
Developing the HelloWorld Solution
6
Module 1: Creating the Application Solution Module Goal:
In this module we will begin building the sample application HelloWorld with the following features: • Cornerstone enable • Single page that displays a static message • Header and Footer user controls • Styling based on a CSS file
7
Procedure 1.1: Creating the HelloWorld web site
1. Create a folder on the c: drive called "HelloWorld_Solution". This is where the application source files will be kept. 2. Open Visual Studio 3. Select FileNewWeb Site… 4. Choose "ASP.NET AJAX-Enabled Web site" (or depending on your Visual Studio installation "ASP .NET AJAX-Enabled Web Application"), set the Location to "c:\HelloWorld_Solution\HelloWord", the Language to "Visual C#" and hit OK
5. In the Solution Explorer window, right click the HelloWorld web site and select Property Page. 6. Add a reference to the Cornerstone.Web.dll assembly from the path your instructor gives you.
8
Procedure 1.2: Adding a HelloWorld page
1. Delete the web page Default.aspx. 2. Right click the HelloWorld web site and add a new web form called "HelloWorldPage.aspx"
3. Open the Source view for HelloWorldPage.aspx and delete all but the first line
4. Right click the HelloWorld.aspx file and select "Set As Start Page" 5. Open the code-behind file for HelloWorldPage.aspx.cs by clicking the '+' next HelloWorldPage.aspx.cs in the Solution Explorer and double clicking the HelloWorldPage.aspx.cs file. 6. Delete all of the "using …" statements at the top of the file except the one for System. 7. Add the statement "using Level3.Cornerstone.Web.WebControls;" to the top of the file under "using System;" 8. Change the base class of this page from "System.Web.UI.Page" to "L3PageTemplate" 9. Delete the entire Page_Load method. 10. Add the following methods: protected override void OnInit(EventArgs e)
Source File Code 1.2: HelloWorldPage.aspx.cs using System; using Level3.Cornerstone.Web.WebControls; public partial class HelloWorldPage : L3PageTemplate { protected override void OnInit(EventArgs e) { base.OnInit(e); EnsureChildControls(); } protected override void CreateChildControls() { base.CreateChildControls(); Controls.Add((L3ControlFactory.CreateLabel("Hello World"))); } }
11
Procedure 1.3: Adding a Header, Footer, and Style Sheet
1. Create a folder in the web site called "Styles" 2. Add the file HelloWorldStyle.css to the Styles folder from the location your instructor gives you. 3. Open Web.config and add the following under the line ""
4. Right click the HelloWorld web site and select "New Folder" 5. Rename the new folder "UserControls". This is where the header and footer for the application pages will be kept. 6. Right click the "UserControls" folder and select "Add New Item…" 7. Add a "Web User Control" called "Header.ascx" 8. Repeat the previous two steps to add "Footer.ascx" 9. Add the following to Header.ascx source view 10. Open the source view for Header.ascx and add the following to the end of the file:
HelloWorld Header
11. Open the source view for Footer.ascx and add the following to the end of the file:
Module 2: Integrating the ValueMapper Module Goal:
In this module we will begin using the ValueMapper class. It is used extensively throughout Cornerstone applications to hold textual content for display values and mapping information for data object relationships. At the end of this module, the HelloWorld solution will have: • New Class Library project called Common which blah, blah, blah. Se the architecture section • A page with static text populated from the ValueMapper
14
Procedure 2.1: Creating the HelloWorld.Common project and adding the ValueMapper
1. Create a new class library project in the solution called HelloWorld.Common using the path c:\HelloWorld_Solution. 2. Delete the Class1.cs file. 3. Add a reference in the project to System.Web
4. Add a reference to the Level3.Cornerstone.Common.dll and Level3.Cornerstone.Web.dll assemblies from the path your instructor gives you. 5. Add a new Class to the HelloWorld.Common project called HWValueMapper.cs.
6. Remove all of the using statements in the HWValueMapper.cs class file. Add the following using statements to the class: 15
using System.IO; using System.Web; using Level3.Cornerstone.Common.ValueMapper;
7. Make the class public. 8. Add a member variable to the class " private static IValueMapper instance;" 9. Add a public property called "Instance" that returns an IValueMapper public static IValueMapper Instance { get { if (instance == null) { string ResourceFile = "App_LocalResources\\HWValueMapper.xml"; FileStream stream = new FileStream(HttpContext.Current.Server.MapPath(ResourceFile), FileMode.Open, FileAccess.Read); instance = ValueMapperFactory.Create(new Stream[] { stream }); } return instance; } }
10. Right click the Common project and build the project.
16
Source File Code 2.1: HWValueMapper.cs using System.IO; using System.Web; using Level3.Cornerstone.Common.ValueMapper; namespace HelloWorld.Common { /// <summary> /// Singleton Wrapper on <see cref="IValueMapper"/> /// public class HWValueMapper { private static IValueMapper instance; private HWValueMapper() { } public static IValueMapper Instance { get { if (instance == null) { string ResourceFile = "App_LocalResources\\HWValueMapper.xml"; FileStream stream = new FileStream(HttpContext.Current.Server.MapPath(ResourceFile), FileMode.Open, FileAccess.Read); instance = ValueMapperFactory.Create(new Stream[] { stream }); } return instance; } }
}
}
17
Procedure 2.2: Creating the ValueMapper resource file
1. Right-click the HelloWorld_Solution web site, and select "App_LocalResources" the "Add ASP.NET Folder" menu. 2. Right click the "App_LocalResources folder and add an XML file called HWValueMapper.xml. 3. Add the following line to the bottom of HWValueMapper.xml: <Mapping xmlns="http://www.level3.com/dotnetcommon/ValueMapperSchema.xsd">
Procedure 2.3: Using the ValueMapper in HelloWorldPage
1. 2. 3. 4.
Add a reference to the HelloWorld.Common project to the HelloWorld web site. Open HelloWorld.aspx.cs Add "using HelloWorld.Common;" Add a line break and a label to the pages Control collection with the following lines in the CreateChildControls method: Controls.Add(L3ControlFactory.CreateBreak()); Controls.Add(L3ControlFactory.CreateLabel(HWValueMapper.Instance.GetPresentationValue("helloworld")));
5. Save all files and browse the page.
20
Source File Code 2.3: HelloWorldPage.aspx.cs using System; using HelloWorld.Common; using Level3.Cornerstone.Web.WebControls; public partial class HelloWorldPage : L3PageTemplate { protected override void OnInit(EventArgs e) { base.OnInit(e); EnsureChildControls(); } protected override void CreateChildControls() { base.CreateChildControls(); Controls.Add((L3ControlFactory.CreateLabel("Hello World"))); Controls.Add(L3ControlFactory.CreateBreak()); Controls.Add(L3ControlFactory.CreateLabel(HWValueMapper.Instance.GetPresentat ionValue("helloworld"))); } }
21
Module 3: Adding a Controller Project Module Goal:
In this module we introduce the Controller layer which routes data between the UI and the service layers. We will process and responds to events from the page. At the end of this module solution will have: • A new class library project called Controller • A controller class to hold logic for the HelloWorldPage
22
Procedure 3.1: Creating the HelloWorld.Web.Controllers project and adding a controller
1. Add a new class library project to the solution called HelloWorld.Web.Controllers on the path c:\HelloWorld_Solution. 2. Delete the Class1.cs file in the new project. 3. Add a new class file called HelloWorldController.cs to the project. 4. Open the class file and make the class definition public. 5. Delete all of the "using" statements. 6. Create a public parameterless method in the HelloWorldController class called GenerateHelloWorldDisplayText that returns the string "Hello World! (from the controller)" 7. Right click the HelloWorld.Web.Controllers project and build the project.
23
Source File Code 3.1: HelloWorldController.cs namespace HelloWorld.Web.Controllers { public class HelloWorldController { public string GenerateHelloWorldDisplayText() { return "Hello World! (from the controller)" } } }
24
Procedure 3.2: Using the HelloWorld Controller
1. 2. 3. 4.
Add a reference to the HelloWorld.Web.Controllers project to the HelloWorld web site. Open the HelloWorldPage.aspx.cs file Add the using statement "using HelloWorld.Web.Controllers;" Add a member variable to the class called "controller" with the statement: HelloWorldController controller = new HelloWorldController();
5. Add a line break and a label control to the page and use the method GenerateHelloWorldDisplayText from the controller to fill the text. 6. Save and view the page in the browser.
25
Source File Code 3.2: HelloWorldPage.aspx.cs using using using using
Module 4: Form Layout and Handling Page Events Module Goal:
In this module we will add page controls for handling a page's layout. We will also begin handling events using a button control. At the end of this module the HelloWorldPage will have: • A L3Border control • A L3Form control • A L3ButtonPanel control • Feedback for the user with the ValidationManager • Two buttons to get and clear labels • An event handler for the button which calls the pages controller to populate a label
27
Procedure 4.1: Adding the L3Form and L3Border controls
1. In CreateChildControls() for HelloWorldPage.aspx.cs, add the line L3Form form = new L3Form();
immediately below base.CreateChildControls();
2. Use the "addRow" method of the new "form" object to add labels to the L3Form: form.AddRow("Static:",L3ControlFactory.CreateLabel("Hello World!")); form.AddRow("From ValueMapper:", L3ControlFactory.CreateLabel(HWValueMapper.Instance.GetPresentationValue("helloworld"))); form.AddRow("From Controller:", controller.GenerateHelloWorldDisplayText());
3. Wrap the L3Form in a L3Border and add it to the pages controls below the last form.addRow statement: Controls.Add(L3Border.WrapControl(form, "This is the L3Border control"));
4. Save and browse the page.
28
Source File Code 4.1: HelloWorldPage.aspx.cs using using using using
public partial class HelloWorldPage : L3PageTemplate { HelloWorldController controller = new HelloWorldController(); protected override void OnInit(EventArgs e) { base.OnInit(e); EnsureChildControls(); } protected override void CreateChildControls() { base.CreateChildControls(); L3Form form = new L3Form(); form.AddRow("Static:",L3ControlFactory.CreateLabel("Hello World!")); form.AddRow("From ValueMapper:", L3ControlFactory.CreateLabel(HWValueMapper.Instance.GetPresentationValue("helloworld" ))); form.AddRow("From Controller:", controller.GenerateHelloWorldDisplayText()); Controls.Add(L3Border.WrapControl(form, "This is the L3Border control")); Controls.Add((L3ControlFactory.CreateLabel("Hello World"))); Controls.Add(L3ControlFactory.CreateBreak()); Controls.Add(L3ControlFactory.CreateLabel(HWValueMapper.Instance.GetPresentat ionValue("helloworld"))); Controls.Add(L3ControlFactory.CreateBreak()); Controls.Add(L3ControlFactory.CreateLabel(controller.GenerateHelloWorldDispla yText())); } }
29
Procedure 4.2: Adding the L3ButtonPanel and Event Handlers
1. Add the following items to the HWValueMapper.xml:
2. Open HelloWorldPage.aspx.cs and add using statements for System.Web.UI.WebControls and Level3.Cornerstone.Web.Images. 3. Add two private member variables of type Label to the HelloWorldPage class called helloWorldFromValueMapper and helloWorldFromController private Label helloWorldFromValueMapper = new Label(); private Label helloWorldFromController = new Label();
4. Optionally, to keep the page cleaner, you can remove the other labels we added in earlier modules. 5. Add the helloWorldFromController and helloWorldFromValueMapper labels to the form with the following below the statement where the L3Form was created: form.AddRow("From ValueMapper:", helloWorldFromValueMapper); form.AddRow("From Controller:", helloWorldFromController);
6. Add an L3ButtonPanel with the statement: L3ButtonPanel buttonPanel = new L3ButtonPanel();
7. Create two buttons and their click event delegates with the following statements: Button getValuesButton = L3ControlFactory.CreateButton(HWValueMapper.Instance.GetPresentationValue("getvalues")); getValuesButton.Click += getValuesButton_Click; Button clearValuesButton = L3ControlFactory.CreateButton(HWValueMapper.Instance.GetPresentationValue("clearvalues")); clearValuesButton.Click += clearValuesButton_Click;
8. Add the buttons to the L3ButtonPanel with the following statements: buttonPanel.AddRightControl(getValuesButton); buttonPanel.AddRightControl(clearValuesButton);
9. If you haven't done so already, remove the L3Border added in the previous procedure . Create a new border and add it to the page with the statements: L3Border border = L3Border.WrapControl(form, " Hello World L3 Border", L3Icon.World, buttonPanel); Controls.Add(border);
10. Add the delegate methods for the buttons' click events with the following: #region Button Events private void getValuesButton_Click(object sender, EventArgs e) { helloWorldFromValueMapper.Text = HWValueMapper.Instance.GetPresentationValue("helloworld");
11. Create the InitializeValues method which resets the values of the labels: private void InitializeValues() { helloWorldFromValueMapper.Text = "Click 'Get Values' to retrieve this."; helloWorldFromController.Text = "Click 'Get Values' to retrieve this."; }
12. Override the base pages OnPreRender event with the following (for organization purposes put this method below the OnInit method): protected override void OnPreRender(EventArgs e) { base.OnPreRender(e); if (!Page.IsPostBack) { InitializeValues(); } }
13. Save and browse the page. Click the two new buttons to make sure they both work.
1. In HelloWorldPage.aspx.cs add a using statement for Level3.Cornerstone.Web.WebControls.Validation. 2. In the CreateChildControls method of HelloWorldPage.aspx.cs add the following statement: ValidationManager.AddInfo("This is an example of event handling and the page lifecycle.");
3. In getValuesButton_Click add the following statement: ValidationManager.AddSuccess("'Get Values' clicked.");
4. In clearValuesButton_Click add the following statement: ValidationManager.AddSuccess("'Clear Values' clicked.");
5. Save and browse the page. Click on the buttons to see how the ValidationManager is displayed.
34
Source File Code: HelloWorldPage.aspx.cs using using using using using using using
In this module we will build a new project for consuming web services which utilizes the Level 3 UDDI registry to different environments. We also establish the pattern of using an Interface to the web service which allows us to create unit tests and stubs for the web service. At the end of the module the HelloWorld solution will have: • New HelloWorld.Services project for consuming web services • A web reference to web services in the application TAI • A ServiceFactory (see Architecture Overview section) • An Interface definition for the TAI web service • A stub for the TAI web service to use during development when the TAI service is not available • A new page that populates a drop down list with data from the TAI web service
37
Procedure 5.1: Creating the HelloWorld.Services project and web reference
1. Create a new class library project in c:\HelloWorld_Solution called HelloWorld.Services. 2. Delete the file Class1.cs 3. Add references to Level3.Cornerstone.UDDIRegistry.dll and Level3.Cornerstone.Common from the distribution folder. 4. Add the following to web.config under the node : <section name="ServiceProperties" type="Blank"/> <section name="uddiConfiguration" type="Level3.Cornerstone.UDDIRegistry.Configuration.UDDIRegistrySection, Level3.Cornerstone.UDDIRegistry, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"/>
5. Add the following to web.config above the node . These values are used later to point at the different environments where the web services are published: <services> <ServiceProperties> <ServiceItem name="TaiWebService" mockOn="false"/>
6. Add a web reference to the HelloWorld.Services project with URL = http://taienv3ws.l3.com/tai/maint/ws?wsdl and Web Reference Name = WebServices.TAI.Maint
38
Procedure 5.2: Creating an Interface for the TAI web service
1. Add a folder to the HelloWorld.Services project called WebServices. 2. Add a new class file in the WebService folder called ITaiWebService.cs 3. Open ITaiWebService.cs and change the class to a public interface by changing "class" to "public interface" 4. Add a "using" statement for HelloWorld.Services.WebServices.TAI.Maint. 5. Add a method signature to the interface for the "FindAllLocState" method in the TAI web service
39
Source File Code 5.2: ITaiWebService.cs using HelloWorld.Services.WebServices.TAI.Maint; namespace HelloWorld.Services.WebServices { public interface ITaiWebService { LocStateVO[] FindAllLocState(LocStateVO locStateVO); } }
40
Procedure 5.3: Creating an implementaion of the ITaiWebService interface
1. Add a new class called TaiWebService to the WebServices directory of the HelloWorld.Services project. 2. Make the class public. 3. Add the following to the using statements: using System.Web.Services.Protocols; using HelloWorld.Services.WebServices.TAI.Maint; using Level3.Cornerstone.UDDIRegistry;
4. Inherit the ITaiWebService interface: class TaiWebService : ITaiWebService
5. Add two private member variables: private string serviceName = typeof(TAI_WebServices).Name; private SoapHttpClientProtocol service;
6. Add a public constructor to the class with the following: public TaiWebService() { service = new TAI_WebServices(); IRegistry registry = RegistryManager.Load(); registry.Bind(serviceName, service); }
7. Implement the method FindAllLocState from the interface with: public LocStateVO[] FindAllLocState(LocStateVO locStateVo) { return Array.ConvertAll((service as TAI_WebServices).findAllLocState(locStateVo), new Converter