Introduction
Ensure that your system has the following minimum software requirements:
Microsoft® Windows® XP or Windows Server™ 2003 operating system Microsoft .NET Framework version 1.1 Microsoft Visual Studio® .NET 2003 Enterprise Architect, Enterprise Developer, or .NET Professional edition development system
UIP Application Blocks can be used to control presentation layer business logic in both Windows-based applications and Web applications. Here in this article, I am going to tell you how to develop the views (Windows Forms or Web pages) for user interaction, define the sequence of flow between the views, and develop a controller to coordinate the navigation between them.
The following are the step-by-step instructions on how to go ahead with the creation UIP blocks.
1.Separate the application into distinct user interface processes. 2.Select a navigator for each user interface process. 3.Determine the state persistence provider. 4.Build the UIP Application Block, and refer to it in your application. 5.Create the controller(s) class by inheriting from the ControllerBase class supplied with the block. Use the base class to define the custom methods for the functionality and navigation within your application. 6.Construct your process flow by starting, resuming, linking, and nesting tasks. 7.Create the views for your specific application type (windows or web), inheriting from the predefined view types in the block. 8.Create the configuration file for defining the state management and process management, the controller class, the views in the process, and the navigation paths between them. 9.Add additional functionality on your business logic if any, you want to be stored in and retrieved from the State class.
To build the UIP Application Block
Open the UIProcess_cs.sln solution (found in the folder). Build the solution. You get two assemblies: Microsoft.ApplicationBlocks.Data.dll Microsoft.ApplicationBlocks.UIProcess.dll
To reference the UIP Application Block in your application
Add a reference to Microsoft.ApplicationBlocks.UIProcess.dll. Add a reference to Microsoft.ApplicationBlocks.Data.dll. Add the following statement at the top of each source file that uses classes from the block
using Microsoft.ApplicationBlocks.UIProcess;
Creating the Controller class
Controller classes expose methods that the views can use to get data or invoke specific functions to pass data to the controller class. The views can access state held by the controller, and can modify the data, but only the controller can perform operations with the data, such as sending it to a Web service. The constructor for your class must accept the navigator you are using as a parameter. You must also call the constructor of the base class.
using Microsoft.ApplicationBlocks.UIProcess;
public class MyController : ControllerBase { public MyController(Navigator navigator) : base(navigator){} // constructor Navigate("AddedData"); // Calling the Navigatemethod }
Add code in your controller class to allow the user to navigate through your workflow process. Write one method for each action a user needs to undertake. Call the Navigate method with the NavigateValue passed as a parameter. The NavigateValue corresponds to the next view or node you specify. If you miss the parameter, UIP will throw an exception because the view is unknown.
UIPManager class is used to start a task. There are many UIP managers available: Graph Navigator, Open Navigator, User Controls Navigator. Use the open navigator to start a new task, by passing the name of the open navigator and the name of the first view as a parameter:
UIPManager.StartOpenNavigationTask("MyOpenNav", "MyFirstViewName");
Creating Views
The next important step is to create the user interface components for the views in your application. Design a view that displays data to, or gets data from, the user and the views should invoke methods on the controllers to set data, but it can retrieve the state of the controller directly.
Inherit the view from the appropriate view class. There are three view classes in the UIP Application Block: WebFormView, WindowsFormView, and WindowsFormControlView. Implement the Initialize method to access custom view information, such as background color. Write code to access the controller for each view in the user interface process. Add navigation code to your views by calling the methods defined in your controller class.
public class WinForm2 : WindowsFormView { private MyController MyController { get{ return (MyController)this.Controller; } } } MyController.AddDataToDatabase(SomeData);
Configuration File
Add a new configuration section to the configuration file to define UIP configuration settings as shown in the following code.
type="Microsoft.ApplicationBlocks.UIProcess.UIPConfigHandler, Microsoft.ApplicationBlocks.UIProcess, Version=1.0.1.0,Culture=neutral,PublicKeyToken=null" />
name="Form1" type="Demo.Form1, Demo, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" controller="MyController" layoutManager="VerticalLayoutManager" stayOpen="true"/> name="Form2" type="Demo.Form2, Demo, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" controller="MyController" /> name="Form3" type="Demo.Form3, Demo, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" controller="MyController" />
startView="Form2" iViewManager="WindowsFormViewManager" name="MyNavigationGraph" state="State" statePersist="SqlServerPersistState" >
Raising Navigation Events
Navigate events are raised after the Navigate method is called on the controller, but before the actual navigation takes place.
Define the NavigateEvent event in the UIPManager class as shown in the following code example.
UIPManager.NavigateEvent += New Microsoft.ApplicationBlocks.UIProcess.UIPManager.NavigateEventHandler (UIPManager_NavigateEvent);
// Define the corresponding event handler as follows:
private void UIPManager_NavigateEvent(object sender, EventNavigateArgs e) { // Some logic that is performed on the navigate event // You can obtain the state from the NavigateEventArgs: e.State // You can change the navigate value like this: // e.State.NavigateValue = someNewNavigateValue; }
UIP Shutdown
Classes that should be notified when a user interface process is complete need to implement the IShutdownUIP interface. The classes that implement the shutdown interface must be registered with the UIPManager class. The IShutdownUIP interface has one public method called Shutdown.
public class StartMeUp : System.Windows.Forms.Form, IShutdownUIP { private void button1_Click(object sender, System.EventArgs e) { // register this class for shutdown UIPManager.RegisterShutdown(this); // hide this form this.Visible = false; _startingTask = new TestTask(); // start UI process UIPManager.StartUserControlsTask("demo",_startingTask); }
// method invoked when UI process is completed public void Shutdown() { // makes form visible again this.Visible = true; } }
Summary
Hope you enjoy developing UIP blocks and try using it in your applications. Any feedbacks, suggesstion are welcome.
|
No responses found. Be the first to respond and make money from revenue sharing program.
|