Add View recipe and Namespace

Topics: CAB & Smart Client Software Factory
Jul 12, 2006 at 5:02 AM
originally posted by: akol_dk

First of all, I think that SC-SF looks great, and I realy look forward to work with version 1.0 in our project.

Is there a bug in the Add View recipe, or is it just me that have misunderstood something. When I use the Add View recipie, it generates interface, view and presenter classes just fine, but it looks like it generates them with the wrong namespaces. The namespace follows the default namespace of the project, and not the folder it is created in. The same thing happends if I add a view in a separate folder.

When I add a Smart Web Reference it has no problem finding out which namespace to use.

Regards
Anders
Jul 12, 2006 at 5:40 AM
originally posted by: timomsft

It's true the reference implementation uses namespaces that reflect the folder structure in the solution. However, this is a convention to help you more easily navigate the solution. Namespaces should provide a logical grouping for the consumers of the related entities in that namespace. The folders are an implemention and organizaiton detail for the developers of the entities - thus they serve two different purposes, even though in practice they can sometimes map one to one (as they do in the reference implementation).

You can modify the View (with presenter) recipe to include the folder name in the namespace if that is convention you want to enforce on every solution. But you may find it preferable to leave it as is, and just refactor the generated code in those times when you want a different namespace.

Cheers,
Tim
Jul 13, 2006 at 6:27 AM
originally posted by: askew

Anytime you add a new item to a folder within a solution in VS2005, the namespace will have that directory appended. Not unique to SCSF...
Jul 13, 2006 at 8:57 PM
originally posted by: akol_dk

Yes, that was also what I thought. However the Add view recipe does not seem to reflect this. If I ask it to create a new view (MyView) in a new folder, it will create a MyView folder and place the IMyView, MyView and MyViewPresenter files in this folder. But it will not add the MyView part to the Namespace of the three files.

I know that namespace and folder names does not have to correspond like they do in Java. However we would like them to correspond as much as possible in the project I'm working on. I may look into modifying the recipe, but I would then have to re-modify the recipe when a new release of SC-SF is ready. Besides it is only three files that are created by the Add view recipe, so it is not that big an issue to modify the namespace of the three files by hand.

Regards
Anders
Jul 20, 2006 at 12:51 PM
originally posted by: timomsft

Hi Anders,

We're out of the mode of continuous drops, so you may find it worthwhile to customize the June 2006 release. In any case, this is a good example of a simple customization, and can be a useful way to gain experience with modifying the package to meet your team's needs. Here's what you need to do:

1. Update the SmartClientDevelopment.xml file so that the user-entered option to create a folder for the view and the name of the folder are passed into the templates.

To do this, update the four Actions (GenerateView, GenerateViewDesigner, GenerateViewInterface, and GenerateViewPresente) that generate the source code files in the CreateView recipe. Add the following two Input elements to each of these actions:

<Input Name="FolderName" RecipeArgument="ViewName" />
<Input Name="CreateViewFolder" RecipeArgument="CreateViewFolder"/>

2. Update the four T4 template files in the Templates\Items\View folder of the SmartClientDevelopment project.

Add the following property declarations to each template file:

<#@ property processor="PropertyProcessor" name="CreateViewFolder" #>
<#@ property processor="PropertyProcessor" name="FolderName" #>

Use the properties to include the foldername in the namespace when appropriate. For example, in the file IView.cs.t4 change the namespace declaration from:

namespace <#= this.TargetNamespace #>

to:

namespace <#= this.TargetNamespace #> <# if (this.CreateViewFolder) { #>.<#= this.FolderName #><# } #>

This will append the folder name to the namespace when the user creates the view in its own folder.

3. Make an additional change to the file View.Designer.cs.t4. It declares a member variable for the Presenter, and uses the namespace in the declaration. You can modify it to use the correct namespace, or, since the two files are created in the same namespace, simply remove the qualifying namespace:

private <#= ClassName #>Presenter _presenter = null;

4. Build and run the Register Guidance Package recipe.

5. Open a new instance of VS and give it a shot.

Cheers,
Tim
Jul 20, 2006 at 7:30 PM
originally posted by: DapinderSingh

HI Tim,

I am working with SCSF-2006 June and tried doing what you have mentioned but encountered an exception "SmartClientDevelopment.xml has been changed and need to install again".

May be I am doing something wrong. Any Suggestions?

Dapinder
Jul 21, 2006 at 4:51 AM
originally posted by: jUrbanowicz

Dapinder ;
If you recieved that message from the solution that you are trying to use the guidance package with, it is just telling you that the guidance package has changed and you need to reinstall it. Here is what we do when we get that message.
- Go to the tools menu. guidance package manager and uninstall the guidance
- Close Visual Studio
- Reopen Visual Studio
- Go to tools, guidance package manager and reinstall the package.
That should do it.

Jay