Getting Started with the Smart Client Software Factory 2010

Getting Started with the Smart Client Software Factory

Are you new to the Smart Client Software Factory? After Installing the Smart Client Software Factory, the best way to get familiar with the Smart Client Software Factory is to do the following:
  • Build a Hello World application. For information about how to do this, see the section, Create Your Hello World Application, that follows.
  • Run the QuickStarts included with the software factory. The BankTeller QuickStart helps you understand the Composite UI Application Block, which is now included with the software factory. For information about the QuickStarts, see the "QuickStarts" topic in the documentation.
  • Download and complete the Hands-on-Labs.
  • Review the "Exploring the Smart Client Software Factory" topic in the documentation.

Just want to review the documentation

If you are in the evaluation phase of the factory, you can download the documentation before downloading the factory. Then when you are ready, you can download the factory.

Create Your Hello World Application

This section describes how to create and display a view using the software factory. To create your first Hello World application, perform the procedures in this section.

Note: The following procedures require the guidance package to be installed.

To create a new smart client application project

  1. In Visual Studio 2008, point to New on the File menu, and then click Project.
  2. In the New Project dialog box, expand Guidance Packages Project, and then select Smart Client Development - April 2008.
  3. Select the Smart Client Application (C#) Visual Studio template.
  4. In the Name box, type HelloWorldApplication, and then click OK.
  5. In the wizard, accept the default settings, select the Show documentation after recipe completes check box, and then click Finish.

To create a Hello World module

  1. In Solution Explorer, right-click the solution, point to Smart Client Software Factory, and then click Add Business Module (C#).
  2. In the Add New Project dialog box, type HelloWorldModule in the Name box.
  3. Click OK.
  4. In the wizard, accept the default settings, select the Show documentation after recipe completes check box, and then click Finish.

To add a Hello World view

  1. In Solution Explorer, right-click HelloWorldModule, point to Smart Client Software Factory, and then click Add View (with presenter).
  2. In the Add New View (with presenter) dialog box, type HelloWorldView in the View box, select the Show documentation after recipe completes check box, and then click Finish.
  3. In Solution Explorer, double-click the file HelloWorldView.cs to view it in the Designer.* Drag a text box onto the view, and set the text to Hello World*.

To configure HelloWorldView to display on the shell's right workspace

1. In Solution Explorer, open ModuleController.cs in the HelloWorldModule project.
2. Add the following code.
C#
 using HelloWorldApplication.Infrastructure.Interface.Constants;

3. In the AddViews method, add the following code.
 C#
 // Add the HelloWorld view (smart part) to the WorkItem and show
 // the view through the RightWorkspace on the shell.
 HelloWorldView hwview = ShowViewInWorkspace< HelloWorldView >(WorkspaceNames.RightWorkspace);

4. Press F5 to build and run your Hello World application.
5. On the File menu, click Exit.

Next, you will associate a command with a menu item to display the Hello World text box.

To extend your first Hello World application to use a toolbar and command

1. Comment out the following code in the AddViews method in the ModuleController.cs file so that the text box does not automatically appear.
 C#
 // Add the HelloWorld view (smart part) to the WorkItem and
 // show the view through the RightWorkspace on the shell.
 HelloWorldView hwview = ShowViewInWorkspace< HelloWorldView >(WorkspaceNames.RightWorkspace);

2. Extend the main toolbar:
a. In Solution Explorer, expand the Constants folder under the HelloWorldModule project, and then double-click CommandNames.cs to open the file.
b. Add the following code to the CommandNames class. This defines the ShowHelloWorldMessage command constant.
 C#
 // A command is an abstraction of UI elements events,
 // such as the click of a button. 
     public const string ShowHelloWorldMessage = "ShowHelloWorldMessage"; 

c. In Solution Explorer, under the HelloWorldModule project, double-click ModuleController.cs to open the file.
d. Add the following code to the ExtendToolStrip method.
 C#
    AddToolStripButton(Constants.CommandNames.ShowHelloWorldMessage, "Hello World");

e. Add the following code to implement the AddToolStripButton method.
 C#
 // This method creates a ToolStripButton and adds it to the
 // MainToolbar using the UIExtensionSites. Then it associates
 // the Click event of the button to a command.
 // UIExtensionSites are points of extension where modules can
 // add UI elements, such as items in a toolbar.
 private void AddToolStripButton(string commandName, string text)
 {
    ToolStripButton button = new ToolStripButton();
    button.Text = text;
    button.ToolTipText = text;
 
    // Add the button to the MainToolBar.
    WorkItem.UIExtensionSites[UIExtensionSiteNames.MainToolbar].Add(button);
 
    // Associate the Click event of the button to a command
    WorkItem.Commands[commandName].AddInvoker(button, "Click");
 }

3. Create a CommandHandler to handle the command you just created. This command displays a HelloWorldView on the RightWorkspace.
 C#
 // A Command Handler is used to handle the firing of a command.
  [CommandHandler(Constants.CommandNames.ShowHelloWorldMessage)]
 public void OnShowHelloWorldMessage(object sender, EventArgs e)
 {
 // Add the HelloWorld view (smart part) to the WorkItem and
 // show the view through the RightWorkspace on the shell.
 HelloWorldView hwview = ShowViewInWorkspace< HelloWorldView >(WorkspaceNames.RightWorkspace);
 }

4. Press F5 to build and run your Hello World application.
5. On the File menu, click Exit.

After you create your Hello World application, you can use the Smart Client Software Factory How-to topics in the documentation to extend your application in the following ways:
  • It can help you create a foundational module.
  • It can help you create a disconnected service agent.
  • It can help you create a Windows Presentation Foundation (WPF) view with a presenter.
  • It can help you map business entities to user interface elements.
  • It can help you publish loosely coupled events.
  • It can help you subscribe to loosely coupled events.
  • It can help you communicate between views.
  • It can help you translate between business entities and service entities.
  • It can help you deploy your application with ClickOnce.

For information about how to perform these activities, see the "Development Activities" topic in the documentation.

More Information

For access to other documentation and resources, or to provide feedback, see the Smart Client Software Factory Web site. For more general information about the goals of this and other patterns & practices deliverables, see the Microsoft patterns & practices Developer Center.

Last edited May 10, 2010 at 5:28 PM by hanz, version 10

Comments

andersoyvind Aug 11, 2010 at 1:04 PM 
@mrooney:
Maybe you should start reflect on why they don't include vb.net-samples in a Best Practices-project. Maybe that is just part of the idea.

npiazza Jan 12, 2010 at 4:17 PM 
Finally got the initial HelloWorldApplication to run, but had to make a number of additional changes to the step-by-step procedures.
1. In project properties for HelloWorldModule, Infrastructure.Module, Infrastructure.Library, and Infrastructure.Layout, I had to remove the prefix "HelloWorldApplication." from the assembly name because the wizard setup code that was not expecting the application name to be prefixed.
2. I had to prebuild Infrastructure.Layout and HelloWorldModule because the dependencies were not setup correctly. In fact, without prebuilding those assemblies, the dependencies cannot be setup because of circular dependencies: Infrastructure.Library depends on Infrastructure.Layout, but Infrastructure.Layout depends on Infrastructure.Library

npiazza Jan 12, 2010 at 3:22 PM 
Additional missing instructions for "To configure HelloWorldView to display..."
1. When building, a ModuleLoadException occurred because Infrastructure.Layout.dll was not found. This appears to be a wizard problem. HelloWorldModule.Interface needs to be marked as dependent on Infrastructure.Layout so that DLL is built first.

2. When building, get error: System.Drawing.Point not referenced in HelloWorldView.Designer.cs. This appears to be another wizard problem. I needed to add a reference to System.Drawing in the HelloWorldModule.Interface project.

npiazza Jan 12, 2010 at 3:03 PM 
The instructions for "To configure HelloWorldView to display..." are missing a step. You need to add another namespace reference: "using HelloWorldApplication.HelloWorldModule.Interface;" in order to access the HelloWorldView class and ShowViewInWorkspace<> method.

jgisabelle Jul 18, 2009 at 6:58 AM 
### Work Around, Adding a View with Presenter without recompiling:###

1. Clean your Solution;
2. Select the project : "Infrastructure.Interface" node (the project c# or VB icon in the solution explorer inside the Solution Folder Infrastructure); then
3. Go to Menu and action "Tools/Guidance Package Manager";
4. Select the desired "Add view with presenter" then click "Execute"
5. Patience;
6. A Form called "Target Element Selection" should pop-up and ask where the view should be added (Target) and you should be able, for instance, to select the "Views" folder of a Business Module;
7. Click "Accept".

Works for me,

Hope this helps,

JGI

bdicroce Apr 25, 2009 at 7:00 PM 
For the problem with the "Add view (with presenter)" menu item now showing, I simply followed the steps from <a href="http://www.codeplex.com/smartclient/Wiki/View.aspx?title=Known%20Issues:%20SC-SF%20April%202008%20with%20Visual%20Studio%202008%20and%20SP1%20Beta&referringTitle=Known%20Issues%20/%20Fixes#RecipesNotDisplayed">here</a>, under the "New SC-SF solutions do not run" section. The last step (step 13) of the directives tells you to "Compile and Register the fixed Guidance Package". That only means that you should enable and execute the "Guidance Package Development" under the Visual Studio's Tools menu (which you'll find in Guidance Package Manager).

Then redo the whole Hello World tutorial from scratch and you should see it by now. Those steps worked for me. It's tedious, it's frustrating, but it's worth it.

mnkeyfeetz Mar 9, 2009 at 9:28 PM 
1. I had the same problem with the View not being available in Visual Studio. I had to uninstall everything, reinstall everything and then install the update for VS SP1 -> http://www.microsoft.com/downloads/details.aspx?familyid=E28205C6-BB07-401B-9A76-804784598BF0&displaylang=en.
2. When I tried following the instructions for this, I kept erroring out. I had to go into the project Properties for each of the projects and change the assembly name by removing "HelloWorldApplication." (e.g. HelloWorldApplication.Infrastructure.Layout.dll to Infrastructure.Layout.dll).

donangel Nov 3, 2008 at 11:28 AM 
I'm experiencing the same issue, which ropardo reported above (Sep 13th). I cannot see "Add view (with presenter)" menu item in the menu. Since this is blocking, I cannot continue with the tutorial, and from there - with my introduction to SCSF. Can someone help with that? I'm using VS 2008 SP1 with latest (I believe) updates from SCSF...

mrooney Sep 16, 2008 at 8:21 AM 
jhollida,
Thanks for the VB support. I do appreciate the time and effort you put forth. Amazing that it took <someone> a year to answer my question. I must begin to question the value of the SCSF when simple VB.Net samples <still> are not available. :(

ropardo Sep 13, 2008 at 10:24 PM 
I am very disappointed with the SCSF. I have had two errors:
1. I created the basic template (the first HOL "Create Smart Client Soluctions") and it did not compile. I had to add the name space as a prefix in the assembly names generated by the wizard!!! IT WORKS BUT IT DOES NOT MAKE SENSE SUCH AN ERROR
2. In ADD VIEW TO HELLO WORLD VIEW of the above article when I right-click HelloWorldModule and I point to Smart Client Software Factory, I do not get the "Add View (with presenter)" menu item. I only see one menu item "Create Diisconnected Service Agent".....
What is happenning?

RodAtWork Jun 27, 2008 at 6:12 PM 
I don't know if this has been mentioned before or not, but when I got to the part in creating my hello world application, of actually getting it to run for the first time, I got an error that said, "A project with an Output Type of Class Library cannot be started directly. In order to debug this project, add an executable project to this solution with references the library project. Set the executable project as the startup project."

The problem was that my HelloWorldModule was set as the startup project, which was wrong. I experimented around until I found that I had to set the Shell project as the startup project.

jhollida Jun 15, 2008 at 4:38 AM 
Here is the VB equivalent...
--------------------------------------------
To start with, I changed the name of the main project from HelloWorldApplication
to HelloWorldApplicationVB so I could have them side by side.

Of course you need to select VB instead of C# in the templates.

The folowing are all of the code snippets.

VB
Imports HelloWorldApplicationVB.Infrastructure.Interface.Constants


VB
' Add the HelloWorld view (smart part) to the WorkItem and show
' the view through the RightWorkspace on the shell.
Dim hwview As HelloWorldView
hwview = ShowViewInWorkspace(Of HelloWorldView)(WorkspaceNames.RightWorkspace)


VB
' A command is an abstraction of UI elements events,
' such as the click of a button.
Public Const ShowHelloWorldMessage As String = "ShowHelloWorldMessage"


VB
' This method creates a ToolStripButton and adds it to the
' MainToolbar using the UIExtensionSites. Then it associates
' the Click event of the button to a command.
' UIExtensionSites are points of extension where modules can
' add UI elements, such as items in a toolbar.
Private Sub AddToolStripButton(ByVal commandName As String, ByVal text As String)
Dim button As ToolStripButton = New ToolStripButton()
button.Text = text
button.ToolTipText = text

' Add the button to the MainToolBar.
WorkItem.UIExtensionSites(UIExtensionSiteNames.MainToolbar).Add(button)

' Associate the Click event of the button to a command
WorkItem.Commands(commandName).AddInvoker(button, "Click")
End Sub


VB
' A Command Handler is used to handle the firing of a command.
<CommandHandler(Constants.CommandNames.ShowHelloWorldMessage)> _
Public Sub OnShowHelloWorldMessage(ByVal sender As Object, ByVal e As EventArgs)
' Add the HelloWorld view (smart part) to the WorkItem and
' show the view through the RightWorkspace on the shell.
Dim hwview As HelloWorldView = ShowViewInWorkspace(Of HelloWorldView)(WorkspaceNames.RightWorkspace)
End Sub

jonathan May 6, 2008 at 8:39 PM 
Hi Jhonny,
I recommend you to check Composite UI Application Block (http://msdn.microsoft.com/en-us/library/aa480450.aspx), it is the core of SCSF.
You can also review the Walkthrough quickstart composed of 4 stages described in this topic: http://msdn.microsoft.com/en-us/library/cc540733.aspx.

Jonathan Cisneros
http://staff.southworks.net/blogs/jcisneros

JhonnyCano Apr 8, 2008 at 9:55 PM 
Is there any "Hello World sample" without using Wizards? my wizards does not appear after I installed, beside, i want to getting really started, without wizards, but i don't know where to start

ss Feb 14, 2008 at 9:05 AM 
Ok, I'm getting the error "The name 'ShowViewInWorkspace' does not exist in the current context", and I'm assuming that I'm not including the right namespaces. I think followed the tutorial correctly.....what did I miss?

mrooney Jul 26, 2007 at 1:36 AM 
So glad there are samples in VB.Net <Not!>