Showing posts with label CAB. Show all posts
Showing posts with label CAB. Show all posts

Thursday, 10 May 2007

Composite UI Application Block - Part Two

There are many elements that make up CAB. When starting out, I found that a lot of the explanations I found just confused me. I will list some of them here and try to explain the way I understand them.

WorkItem
This is the most important element in CAB. It is basically a container that manages all the objects required to accomplish a certain task.
For example, I have a WorkItem for managing Products. It manages all of the commands/views and presenters required to list, view and edit Products.
The Views might be ProductsListView and ProductsDetailsView. WorkItem also contains state objects to manage the state of the workitem (eg: What product has been selected?).
The workitem contains all of the objects necessary to complete the task - this means the presenters/views never have to look outside of the WorkItem.
Every module created will contain a WorkItem. The WorkItem is controlled by a class called the WorkItemController which is used to initialize and run the module/workitem.
There is a RootWorkItem which is the toplevel WorkItem. All other WorkItems are connected through the root WorkItem.

SmartPart
SmartParts are the visual components of a module (basically a view). They are usually a UserControl that is shown somewhere on the main form.
WorkItems can contain one or more SmartParts to display. It is up to the WorkItem to decide when/where to display the SmartPart.

Workspaces
Workspaces are UI controls that can display SmartParts. A workspace decides how to display the SmartPart (eg: DockedPanel, Frame,Tab etc). WorkItems have a Workspace collection that contains all of the Workspaces it has available to use. WorkItems then display a SmartPart by adding it to a Workspace.
Workspaces need to be added to a WorkItem. These Workspaces are then visible to this WorkItem, as well as all of it's children WorkItems.
You can create a Workspace from any type of control by implementing the IWorkspace interface.

Services
The WorkItem class includes a Services collection that you can use to register/access services. A service is registered as an interface type - This allows you to change the implementation of the service without affecting anything else. For example, you could register a database access service, and then switch to another type of database at a later date.
You can use services for things such as logging, database access etc.

Event Broker
The event broker allows you to create events and have classes publish/subscribe to these events without knowing about one another. An event have one or more publishers, as well as one or more subscribers. It's a way to pass events and data around the application without having to set dependencies.

I think these are the parts of CAB that I use the most. In my next post, I will explain how these fit together and post some guidelines to follow when developing a CAB application. These guidelines will make debugging/future modifications easier and should keep your entire project well structured and clean.

Wednesday, 9 May 2007

Composite UI Application Block - Part One

A few months ago I discovered this thing called CAB - Composite UI Application Block.
I was looking for a way to build an application that could load multiple modules and merge them all together seamlessly. I also wanted to have the ability to easily switch data providers at a later date, meaning that I could integrate any number of accounting/product databases into my application.

I read that CAB allows you to seperate your code into independent modules. These modules could interact with each other and the main shell without having to set dependencies. At this point, I realised that CAB was exactly what I was looking for.

CAB has a steep learning curve - it took me a while to work out how the modules fit together.
I've decided to write a series of posts to keep a reference of what I know and to help other developers get started.

What is cab?
Rather than rewrite a definition, I've "borrowed" the one from Cabpedia.com.
(Cabpedia is an excellent resource for learning more about CAB. Many of the questions I initially had were answered there.)

CAB stands for the Composite UI Application Block, and it's a set of .NET 2.0
classes designed to make it easier to build complex Windows Forms
applications. Perhaps the most important way it helps you simplify your
applications is through decoupling the pieces of code that make up a large
application.

CAB also provides support for decoupling the elements
in the user interface. This means you can often make major changes to how
the UI is put together without having to change any of the modules that make up
an application. For example, you might have an Outlook-style user interface
and then decide you want to change it to a web-style interface. No problem.
Just change the UI shell and the modules will load themselves into the new
locations as you've defined it.

When you start a CAB application, you start by creating a UI shell. This is the main form that might include the menu, toolbars, etc.
Next you add one or more Workspaces to the form. These are the locations where the different elements of the UI will appear when the application is running.
Finally, you create one or more modules that contain either elements that will appear in the UI, or Services that will be available for use by other classes.

CAB is perfect for building modular applications. Extending your application is as simple as adding the new module's compiled DLL to the ProfileCatalog.xml file.

Getting Started
It took me a while to get CAB installed and working properly.
Here are the downloads required:

Guidance Automation Extensions - Download
Guidance Automation Toolkit - Download
Composite UI Application Block - Download C# Download VB
Enterprise Library - Download
Smart Client Software Factory - Download

All these toolkits/libraries are used by CAB. Download and install them in the order above. It shouldn't take more than 30 minutes to successfully install everything.

Once these are installed, have a look at the Hands On Labs and this Hello World tutorial from Cabpedia.com.

There are many elements that make up CAB.
In my next post, I will list these elements and explain a bit more about them and what they do.

Monday, 7 May 2007

TMS

TMS
I am building an application called TMS. The main purpose of this application is to speed up the sales process, from creating the sale to dispatching the goods.

I have developed the application using the Composite Application UI Block (CAB), which has significantly cut development time (after getting over the learning curve).
The application is split into many smaller modules.
The main exe is just a shell that hosts these other modules.
The CAB architecture allows these modules to interact with the shell's (and other modules) services and toolbars without having any dependency on any of the modules.

I've also designed the data providers to work independently - The data providers/modules only interact with a DataModel object. The module requests to retrieve SalesOrder record 50, and any datasources that inherit the ISalesOrder interface can respond to this request.
This will allow users to simply plug in a new data provider module for other accounting databases etc.


Extension Manager
I've just finished working on an extension manager for TMS. This allows users to download new modules for their TMS application - User's can basically build and customise their application to suit their needs.
It also checks for updates using a Web Service. The assembly version numbers are compared, and the user is asked if he/she wants to download the update.

Layout Problems
The whole idea behind TMS was that every module would be independent. The application has Layout modules that define the structure for the user interface. One of these layout modules in TMS creates the toolbars at the top of the window and exposes them as a UIExtension. Other modules can access UIExtensions and add/remove buttons.
The problem I am having I am creating new instances of this ButtonItem class and adding them to the toolbar. This means that if I ever create a new layout module, I cannot change the toolbar type because the modules are dependent on this toolbar type.
This is the problem I am trying to solve now.

I will post again later today