First, create a new smart client software factory solution in vs. net. Initially, a source folder is automatically generated, and then a sub-folder named infrastructure
Several infrastructure (infrastructure) Projects
Infrastructure. Interface
Infrastructure. Layout
Infrastructure. Library
Infrastructure. Module
There is also a startup project shell. The shellform under shell is the entry point of the entire program. This shellform is not the final interface of the program, but a "shell ", content above the runtime is dynamically loaded
Study its code
Public sub new () <br/> initializecomponent () <br/> _ layoutworkspace. Name = workspacenames. layoutworkspace <br/> end sub
What is the concept of workspacenames. layoutworkspace? I will study it later.
To add your own view to this "shell", you must use the scsf template to create a module project first.There are two types of modules available: bussiness and functional
- Functional Module -- only provides some services to other modules, does not implement a use-case, does not contain a workitem
- Business module-implement a series of related use cases, including workitems.
The bussiness type is selected here. Some options above the menu can be selected to generate the corresponding unit test project and interface project.
After a module project is generated, Several folders constants, services, and views are generated. There are also two classes of modulecontroller, moduleinitializer
Here, we only focus on the modulecontroller class. It inherits from workitemcontroller. What kind of class is workitemcontroller? It comes from infrastructure. Interface and looks at its source code.
Imports Microsoft. practices. compositeui <br/> imports smartclient. infrastructure. interface. services <br/> ''' <summary> <br/> ''' base class for a workitem controller. <br/> ''' </Summary> <br/> Public mustinherit class workitemcontroller <br/> implements iworkitemcontroller <br/> private _ workitem as workitem <br/>'' '<summary> <br/> ''' gets or sets the work item. <br/> ''' </Summary> <br/> ''' <value> the work item. </value> <br/> <servicedependency () >_< br/> Public Property workitem () as workitem <br/> Get <br/> return _ workitem <br/> end get <br/> set (byval value as workitem) <br/> _ workitem = value <br/> end set <br/> end property <br/> Public readonly property actioncatalogservice () as iactioncatalogservice <br/> Get <br/> return _ workitem. services. get (of iactioncatalogservice )() <br/> end get <br/> end property <br/> ''' <summary> <br/> ''' creates and shows a smart part on the specified workspace. <br/> ''' </Summary> <br/> ''' <typeparam name = "tview"> the type of the smart part to create and show. </typeparam> <br/> ''' <Param name = "workspacename"> The Name Of The workspace in which to show the smart part. </param> <br/> ''' <returns> the new Smart part instance. </returns> <br/> protected overridable function showviewinworkspace (of tview) (byval workspacename as string) as tview <br/> dim view as tview = workitem. smartparts. addnew (of tview) () <br/> workitem. workspaces (workspacename ). show (view) <br/> return view <br/> end function <br/> ''' <summary> <br/> ''' shows a specific smart part in the workspace. if a smart part with the specified id <br/> ''' is not found in the <see CREF = "workitem. smartparts "/> collection, a new instance <br/> ''' will be created; otherwise, the existing instance will be re used. <br/> ''' </Summary> <br/> ''' <typeparam name = "tview"> the type of the smart part to show. </typeparam> <br/> ''' <Param name = "viewid"> the ID of the smart part in the <see CREF = "workitem. smartparts "/> collection. </param> <br/> ''' <Param name = "workspacename"> The Name Of The workspace in which to show the smart part. </param> <br/> ''' <returns> the smart part instance. </returns> <br/> protected overridable function showviewinworkspace (of tview) (byval viewid as string, byval workspacename as string) as tview <br/> dim view as tview <br/> If workitem. smartparts. contains (viewid) Then <br/> View = workitem. smartparts. get (of tview) (viewid) <br/> else <br/> View = workitem. smartparts. addnew (of tview) (viewid) <br/> end if <br/> workitem. workspaces (workspacename ). show (View) <br/> return view <br/> end function </P> <p> Public overridable sub run () implements iworkitemcontroller. run <br/> end sub <br/> end class
It is basically manipulating the workitem and iview objects. here we need to clarify several concepts.
What is workspace? What is smartparts?
Let's take a look at Microsoft's official explanation of smartparts.
Microsoft's cab documentation defines a smartpart as 'a view of data (in the MVC pattern) such as a control, a Windows form, or a Wizard Page
In Microsoft's cab document, smartpart is defined as a data view (in MVC mode), such as controls, Windows Forms, and Wizard pages.
Let's just think of it as a control, or it should be said that it is a control other than a container.
Let's look at Microsoft's official explanation of workspace.
The components that encapsulate a participant visual layout of controls and smartparts, such as within tabbed pages
A specific component that encapsulates and controls visual layout and smartparts, such as "tab"
Literally,The workspace is similar to the Container Control we usually use in projects. It is a container that carries other controls.
Workspaces are themselves controls that allow other controls to be laid out within them, in particle they are designed to allow smartparts to be laid out within them.
Workspaces themselves allow other controls to be put into them, especially they are designed to put smartparts into them.
See, this sentence is clear enough.
The difference between workspaces and common container controls is that they use the cab dependency injection container (workitmes)
We can use the addnew keyword in the workspaces set to create a workspace. However, we do not need to do this. Drag and Drop a workspace to the screen. objectbuilder automatically identifies the workspace and adds it to the appropriate collection.
There are several types of workspace. For details, refer to the following page:
Http://richnewman.wordpress.com/2007/11/24/workspace-types-introduction-to-the-cabscsf-part-17/
For more information, see my previous articles.
Http://blog.csdn.net/lee576/archive/2011/05/03/6386857.aspx
Take Office Excel as an example. The roles they play in Excel are clear at a glance.
Back to the main line,Workitem is the business logic, and workitemcontroller is the business logic controller. It does a very simple job to avoid coupling between views and workitems.The view does not know the existence of the workitem, nor does the workitem know the view. They are only coupled with the workitemcontroller. from the code point of view, workitemcontroller is nothing more than telling the view under which workspace it is working. This is the classic MVC mode, 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 abstract. "an independent part of the cab program is used for runtime containers of objects and services ."
Back to the modulecontroller class we just generated. If we want to display our own view in the main form, how can we do this?
First, weIn the views folder, right-click the scsf template menu and choose add view (with presenter)
Here we name view as demo, and three files will be automatically generated: demoview. VB, demoviewpresenter. VB, and idemoview. VB.
Ha, typical MVP mode!
The demoviewpresenter class inherits from the presenter base class. What does the presenter do?
Imports Microsoft. practices. compositeui <br/> imports system <br/> imports Microsoft. practices. compositeui. smartparts <br/> Public mustinherit class Presenter (of tview) <br/> implements idisposable <br/> private _ view as tview <br/> private _ workitem as workitem <br/> private _ disposed as Boolean = false <br/> Public property view () as tview <br/> Get <br/> return _ view <br/> end get <br/> set (byval value as tview) <br/> _ view = value <br/> onviewset () <br/> end set <br/> end property <br/> <servicedependency ()> _ <br/> Public Property workitem () as workitem <br/> Get <br/> return _ workitem <br/> end get <br/> set (byval value as workitem) <br/> _ workitem = value <br/> end set <br/> end property <br/> protected overridable sub closeview () <br/> dim locator as services. iworkspacelocatorservice = workitem. services. get (of services. iworkspacelocatorservice) () <br/> dim wks as iworkspace = locator. findcontainingworkspace (workitem, view) <br/> if not wks is nothing then <br/> wks. close (View) <br/> end if <br/> end sub <br/> Public overridable sub onviewready () <br/> end sub <br/> protected overridable sub onviewset () <br/> end sub </P> <p> Public overridable sub oncloseview () <br/> end sub <br/> ''' <summary> <br/> ''' See <see CREF = "system. idisposable. dispose "/> for more information. <br/> ''' </Summary> <br/> Public sub dispose () implements idisposable. dispose <br/> if not _ disposed then <br/> dispose (true) <br/> GC. suppressfinalize (me) <br/> end if <br/> end sub <br/> ''' <summary> <br/> ''' called when the object is being disposed or finalized. <br/> ''' </Summary> <br/> ''' <Param name = "disposing"> true when the object is being disposed (and therefore can <br/> ''' access managed members ); false when the object is being finalized without first <br/> ''' having been disposed (and therefore can only touch unmanaged members ). </param> <br/> protected overridable sub dispose (byval disposing as Boolean) <br/> If disposing then <br/> if not _ workitem is nothing then <br/> if not me. view is nothing then <br/> oncloseview () <br/> _ workitem. items. remove (Me. view) <br/> end if </P> <p> _ workitem. items. remove (me) <br/> end if </P> <p> _ disposed = true <br/> end sub <br/> end class
Set the current workitem, current view, and associate them. Then, three virtual functions are added to the three life cycles of the view, the purpose is to facilitate rewriting in child classes to achieve the purpose of expansion, which is the support of events. At last, it is responsible for analyzing itself and removing the view in workitem. Why is it necessary to remove the view? This is nothing more than releasing resources. Originally, the view is dynamically added. Remove the relationship between view and workitem when you close it.
Finally, how can we add the newly created demo to the main form?
Return to the modulecontroller class and write
Private sub addviews () <br/> 'todo: Create the module views, add them to the workitem and show them in <br/> 'a workspace. <br/> 'to create and add a view you can customize the following sentence <br/> 'showviewinworkspace (of sampleview) (workspacenames. sampleworkspace) <br/> showviewinworkspace (of demoview) (workspacenames. layoutworkspace) <br/> end sub
This is to set the view to a workspace, workspacenames. layoutworkspace
Workspacenames is a custom constant class.
Public class workspacenames <br/> Public const layoutworkspace as string = "layoutworkspace" <br/> Public const modalwindows as string = "modalwindows" <br/> Public const leftworkspace as string =" leftworkspace "<br/> Public const rightworkspace as string =" rightworkspace "<br/> end class
Public const layoutworkspace as string = "layoutworkspace"
This is equivalent to Microsoft. Practices. compositeui. winforms. deckworkspace.
The evidence is here in shellform. Designer. VB.
Private sub initializecomponent () <br/> me. _ layoutworkspace = new Microsoft. practices. compositeui. winforms. deckworkspace <br/> me. suspendlayout () <br/> '_ layoutworkspace <br/>' <br/> me. _ layoutworkspace. dock = system. windows. forms. dockstyle. fill <br/> me. _ layoutworkspace. location = new system. drawing. point (0, 0) <br/> me. _ layoutworkspace. name = "_ layoutworkspace" <br/> me. _ layoutworkspace. Size = new system. drawing. size (698,516) <br/> me. _ layoutworkspace. tabindex = 0 <br/> me. _ layoutworkspace. TEXT = "_ layoutworkspace" <br/> '<br/> 'shellform <br/>' <br/> me. autoscaledimensions = new system. drawing. sizef (6.0 !, 13.0 !) <Br/> me. autoscalemode = system. windows. forms. autoscalemode. font <br/> me. clientsize = new system. drawing. size (698,516) <br/> me. controls. add (Me. _ layoutworkspace) <br/> me. name = "shellform" <br/> me. TEXT = "shellform" <br/> me. resumelayout (false) <br/> end sub
There are several other constants, which are used in showviewinworkspace and details will be clarified later.