Smart Client software Factory: Simply create a new interface and display it

Source: Internet
Author: User

First, create a new smart Client Software Factory solution on vs.net. The original automatically generated is a source folder, then a subfolder named infrastructure

Several infrastructure (infrastructure) projects

Infrastructure.interface

Infrastructure.layout

Infrastructure.library

Infrastructure.module

There is also a startup Project Shell,shell under the Shellform for the entire program entry point, this shellform is not the final interface of the program, just a "shell", the contents of the runtime is dynamically loaded up

Look at the code for it.

Public Sub New () initializecomponent () _layoutworkspace.name = Workspacenames.layoutworkspace End Sub

What is the concept of workspacenames.layoutworkspace this workspace, and then to study

then to this "shell" to add your own view, you will use SCSF template to create a new module project , there are two types of module can choose, bussiness and functional

Functional module-just provides some services to other modules, does not implement a use-case, does not include a WorkItem business module-implements a series of related use cases, including WorkItems.

I choose the bussiness type, the menu above some options, you can choose to generate the corresponding unit test project and Interface project.

After the module project is generated, several folder Constants,services,views are generated. There are also two other classes of Modulecontroller,moduleinitializer

Here we focus on the Modulecontroller class, which inherits from Workitemcontroller,workitemcontroller is a class. It comes from under the Infrastructure.interface and look at its source code

Imports Microsoft.Practices.CompositeUI Imports SmartClient.Infrastructure.Interface.Services ' <summary> ' ' Base class for a WorkItem controller. ' </summary> public MustInherit Class workitemcontroller Implements iworkitemcontroller Private _workitem as Work Item ' <summary> ' Gets or sets the work item. "</summary>" <value>the work item.</value> <servicedependency () > _ WorkItem () as WorkItem Get Return _workitem End Get Set (ByVal value as WorkItem) _workitem = value End Set End Property Pu Blic ReadOnly Property Actioncatalogservice () as Iactioncatalogservice Get Return _workitem.services.get (of Iactioncatalogservice) () End Get End Property "<summary>" creates and shows a smart part on the specified work Space. ' </summary> ' <typeparam name= "TView" >the type of the smart part to create and show.</typeparam> ' ' <param name= ' workspacename ' >the name of the workspace in which TO Show the Smart part.</param> ' <returns>the new Smart part instance.</returns> Protected Overridable Function showviewinworkspace (of TView) (ByVal workspacename as String) as TView Dim view as TView = WorkItem.SmartParts.Ad Dnew (of TView) () workitem.workspaces (workspacename). Show (view) Return view End Function ' <summary> ' shows a specific smart part in the workspace. If a smart part with the specified ID "was not found in the <see cref=" Workitem.smartparts "/> Collection, a new in Stance "would be created; Otherwise, the existing instance would be re used. ' </summary> ' <typeparam name= ' TView ' >the type of the smart part to Show.</typeparam> ' <param Name= "viewId" >the ID of the smart part in the <see cref= "Workitem.smartparts"/> collection.</param> "&l T;param name= "workspacename" >the name of the workspace in which to show the smart part.</param> ' &LT;RETURNS&G T The smart part INSTANCE.&LT;/Returns> Protected Overridable Function showviewinworkspace (of TView) (ByVal viewId as String, ByVal workspacename as Str ing) as TView Dim view as TView If WorkItem.SmartParts.Contains (viewId) then view = WorkItem.SmartParts.Get (of TView) (view ID) Else view = WorkItem.SmartParts.AddNew (of TView) (viewId) End If workitem.workspaces (workspacename). Show (view) Return view End Function public Overridable Sub Run () Implements Iworkitemcontroller.run End Sub End class&nbsp ;

It's basically manipulating WorkItem and iview, and there are a couple of concepts to be clarified here.

What is workspace? What is Smartparts?

First look at Microsoft's official explanation for Smartparts

Microsoft ' s CAB documentation defines a smartpart as ' a view of data (in the MVC pattern) such as a control, a Windows for M, or a wizard page

Microsoft's CAB document defines Smartpart as a view of data (in MVC mode) such as controls, Windows Forms, wizard pages

Think of it as a control, or it's a control other than a container.

And look at Microsoft's official explanation for workspace.

The components that encapsulate a particular visual layout of controls and smartparts, such as within tabbed pages

A specific component that encapsulates the control of visual layout and smartparts, such as "tabs"


Literally,Workspace is actually similar to the container control used in our usual project, which is a container that hosts other controls.

Workspaces is themselves controls that allow the other controls to being laid out within them,in particular they is designed to Allow Smartparts to is laid out within them.

Workspaces They allow other controls to be placed in them themselves, especially if they are designed to let smartparts into them .

Look, this sentence has been said to be clear enough.

The difference between workspaces and ordinary container controls is that they take advantage of the CAB Dependency injection container (workitmes)

We can create a workspace with the AddNew keyword in the Workspaces collection, but we don't need to do that. You can drag and drop a workspace to the screen, ObjectBuilder will automatically recognize the workspace and add it to the appropriate set

Workspace are divided into several types, depending on the following pages

http://richnewman.wordpress.com/2007/11/24/workspace-types-introduction-to-the-cabscsf-part-17/

Specific concept review, refer to my previous article

Http://blog.csdn.net/lee576/archive/2011/05/03/6386857.aspx

With Office Excel, it's clear that they have their roles in excel at a glance.

Back to the main line,WorkItem is the business logic, Workitemcontroller is the business logic controller. The work it does is simple, avoiding the coupling between the view and the WorkItem , and the view does not know the existence of WorkItem, WorkItem also do not know the view, they are only with the workitemcontroller coupling. From the code point of view, Workitemcontroller's job is to tell the view, work under which workspace, This is the classic MVC pattern, isn't it?

WorkItem: A runtime container of the objects and services used by a discrete part of a CAB application. Think of it as a logical sub-process or sub-application. It is the basic unit of software scoping in a CAB application. Your business logic lives in one or more workitems.

The first sentence in English seems to be very abstract, "a separate part of the CAB program that is used for objects and the runtime container of the service."

Say back to the Modulecontroller class we just generated, what if we want to show our own view in the main form?

First, in the Views folder, right-click on the SCSF Template menu and choose Add View (with presenter).

Here we give the view named demo, will automatically generate three files, Demoview.vb,demoviewpresenter.vb,idemoview.vb

Ah, a typical MVP model!

Demoviewpresenter class inherits from presenter base class, what did presenter do?

Imports Microsoft.Practices.CompositeUI Imports System Imports Microsoft.Practices.CompositeUI.SmartParts Public MustInherit Class Presenter (of TView) Implements IDisposable private _view as TView private _workitem as WorkItem private _disposed as Boolean = False Public Property View () as TView Get Return _view End get Set (ByVal value as TView) _view = VA Lue Onviewset () End Set End Property <servicedependency () > _ Public Property WorkItem () as WorkItem Get Return _work Item End Get Set (ByVal value as WorkItem) _workitem = value End Set End Property Protected Overridable Sub CloseView () Dim Locator as Services.iworkspacelocatorservice = WorkItem.Services.Get (of Services.iworkspacelocatorservice) () Dim wks As Iworkspace = Locator. Findcontainingworkspace (WorkItem, View) If not wks are nothing then wks. Close (View) End If End Sub Public Overridable Sub Onviewready () End Sub Protected Overridable Sub Onviewset () End Sub Publ IC Overridable Sub Oncloseview () End Sub ' <summary> ' See <see cref= "System.IDisposable.Dispose"/> For more information. ' </summary> public Sub Dispose () Implements idisposable.dispose If not _disposed then Dispose (True) GC. SuppressFinalize (Me) End If end Sub ' <summary> ' called when the object is being disposed or finalized. "</summary>" <param name= "disposing" >true when the object is being disposed (and therefore can ' acces s managed members); False when the object is being finalized without first "has been disposed (and therefore can only touch unmanaged me mbers) .</param> Protected Overridable Sub Dispose (ByVal disposing as Boolean) if disposing then if isn't _workitem is Nothing and if not Me.view are nothing Then Oncloseview () _workitem.items.remove (Me.view) End if _workitem.items.remove (Me ) End If End If _disposed = True End Sub End class 

Set the current WorkItem, the current view, associate them, and then put three virtual functions in the three life cycle of the view in order to make it easier to rewrite the subclass to achieve the purpose of the extension, which is the event support. Finally, it is responsible for the destruction of itself, and the removal of the view in the WorkItem. Why remove view? Just to release resources, the view is dynamic plus go. The relationship between view and WorkItem is removed when you close.

Finally, what if we were to add the newly created demo to the main form?

Back to the Modulecontroller class, write on

Private Sub addviews () ' Todo:create the Module views, add them to the WorkItem and show them in ' a Workspace. ' To create and add a view you can customize the following sentence ' Showviewinworkspace (of Sampleview) (WORKSPACENAMES.SA Mpleworkspace) Showviewinworkspace (of DemoView) (workspacenames.layoutworkspace) End Sub

This is the view set to a workspace above, workspacenames.layoutworkspace

Workspacenames is a custom constant class

Public Class workspacenames Public Const layoutworkspace As String = "layoutworkspace" Public const modalwindows As String = "Modalwindows" Public Const leftworkspace As String = "leftworkspace" Public Const rightworkspace As String = "Rightwor Kspace "End Class

Public Const layoutworkspace as String = "Layoutworkspace"

This is the equivalent of Microsoft.Practices.CompositeUI.WinForms.DeckWorkspace.

The evidence is here, ShellForm.Designer.vb inside.

Private Sub InitializeComponent () Me._layoutworkspace = New Microsoft.Practices.CompositeUI.WinForms.DeckWorkspace Me.suspendlayout () ' _layoutworkspace ' Me._layoutworkspace.dock = System.Windows.Forms.DockStyle.Fill me._ Layoutworkspace.location = New System.Drawing.Point (0, 0) me._layoutworkspace.name = "_layoutworkspace" me._ Layoutworkspace.size = New System.Drawing.Size (698, 516) me._layoutworkspace.tabindex = 0 Me._layoutworkspace.text = "_ Layoutworkspace "' shellform ' me.autoscaledimensions = New System.Drawing.SizeF (6.0!, 13.0!) Me.autoscalemode = System.Windows.Forms.AutoScaleMode.Font me.clientsize = New System.Drawing.Size (698, 516) ME.CONTROLS.ADD (me._layoutworkspace) Me.Name = "Shellform" Me.Text = "Shellform" Me.resumelayout (False) End Sub

There are a few other constants, specifically used in the Showviewinworkspace, and then clear the details

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.