Add Page (with presenter) Recipe

The guidance package includes the recipe named Add Page (with presenter). After you register (or install) the guidance package, the recipe is available on the Solution Explorer shortcut menu that appears when you right-click a folder in a Web site or the Web site root node. Figure 1 illustrates the recipe menu.
AddPageWithPresenterRecipeMenu.png
Figure 1
The Add Page (with presenter) recipe menu.

When you run the recipe, the recipe framework displays a wizard that you can use to customize the generated code. Figure 2 illustrates the wizard.
AddPageWithPresenterRecipeWizard.png
Figure 2
The Add Page (with presenter) recipe wizard.

Implementation Details

You can find the recipe definition split across the files CreateWebClientFactoryView.xml and CreateWebClientFactoryViewCommon.xml (these files are located in subfolders under the Recipes folder of the WebClientFactoryPackage project).
You use the HostData section in a recipe definition to specify where in the Visual Studio interface the recipe will be shown. In the CreateWebClientFactoryView.xml file, four command bars are defined in the HostData section.

<HostData>
  <Icon ID="689" />
  <CommandBar Menu="WCSFWebProjectFolderItem" />
  <CommandBar Menu="WCSFWebProject" />
  <CommandBar Menu="
  <CommandBar Menu="
</HostData>

The first command bar is associated with the WCSFWebProjectFolderItem menu; the second command bar is associated with the WCSFWebProject menu; the third command bar is associated with the WCSFWebApplicationProject menu; the forth command bar is associated with the WCSFWebApplicationProjectFolder menu.
The WCSFWebProjectFolderItem menu is displayed when the user right-clicks a folder in a Web site in Solution Explorer; the WCSFWebProject menu is displayed when the user right-clicks a Web site node; the WCSFWebApplicationProject menu is displayed when the user right-clicks a Web Application project node; the WCSFWebApplicationProjectFolder menu is displayed when the user right-clicks a folder in a Web Application project node in Solution Explorer.
The WCSFWebProjectFolderItem menu, the WCSFWebProject menu, the WCSFWebApplicationProject menu, and the WCSFWebApplicationProjectFolder menu are defined in the file WebClientFactoryPackage.xml located in the root of the WebClientFactoryPackage project.

<Menu Name="WCSFWebProject" Text="Web Client Factory" Priority="1">
  <CommandBar Name="Web Project"/>
</Menu>
<Menu Name="WCSFWebProjectFolderItem" Text="Web Client Factory" Priority="1">
  <CommandBar Name="Web Folder"/>
</Menu>
<Menu Name="WCSFWebApplicationProject" Text="Web Client Factory" Priority="1">
  <CommandBar Guid="D309F791-903F-11D0-9EFC-00A0C911004F" ID="1026"/>
</Menu>
<Menu Name="WCSFWebApplicationProjectFolder" Text="Web Client Factory" Priority="1">
  <CommandBar Guid="D309F791-903F-11D0-9EFC-00A0C911004F" ID="1073"/>
</Menu>

The files created by the recipe (the page implementation, the presenter, and the page's interface) are generated from T4 templates. You can use T4 templates to write complex templates with embedded code that gets executed when the template unfolds. The following actions in the recipe definition unfold the T4 templates for the page's files.

<Action Name="GenerateViewWebFile"
      Type="TextTemplateAction">
  <Input Name="Template" RecipeArgument="T4ViewPath"/>
  <Input Name="ModuleName" RecipeArgument="ModuleName"/>
  <Input Name="ViewName" RecipeArgument="ViewName"/>
  <Input Name="IsWCSFSolutionWAP" RecipeArgument="IsWCSFSolutionWAP"/>
  <Input Name="WebsiteNamespace" RecipeArgument="WebsiteNamespace"/>
  <Output Name="Content" />
</Action>
<Action Name="GenerateViewCodebehind"
Type="TextTemplateAction">
  <Input Name="Template" RecipeArgument="T4ViewCodebehindPath"/>
  <Input Name="ModuleName" RecipeArgument="ModuleName"/>
  <Input Name="ViewName" RecipeArgument="ViewName"/>
  <Input Name="ModuleNamespace" RecipeArgument="ModuleNamespace"/>
  <Output Name="Content" />
</Action>
<Action Name="GenerateViewDesigner"
Type="TextTemplateAction"
Condition="$(IsWCSFSolutionWAP)">
  <Input Name="Template" RecipeArgument="T4ViewDesignerPath"/>
  <Input Name="ModuleName" RecipeArgument="ModuleName"/>
  <Input Name="ViewName" RecipeArgument="ViewName"/>
  <Output Name="Content" />
</Action>
<Action Name="GenerateViewPresenter"
      Type="TextTemplateAction">
  <Input Name="Template" RecipeArgument="T4ViewPresenterPath"/>
  <Input Name="ModuleName" RecipeArgument="ModuleName"/>
  <Input Name="ViewName" RecipeArgument="ViewName"/>
  <Input Name="ModuleNamespace" RecipeArgument="ModuleNamespace"/>
  <Input Name="ViewsFolder" RecipeArgument="ViewsFolder"/>
  <Output Name="Content" />
</Action>
<Action Name="GenerateViewInterface"
Type="TextTemplateAction">
  <Input Name="Template" RecipeArgument="T4ViewInterfacePath"/>
  <Input Name="ViewName" RecipeArgument="ViewName"/>
  <Input Name="ModuleNamespace" RecipeArgument="ModuleNamespace"/>
  <Input Name="ViewsFolder" RecipeArgument="ViewsFolder"/>
  <Output Name="Content" />
</Action>

Note:
For detailed information about T4 templates, see the Guidance Automation Toolkit documentation.You can only add pages to modules with names that are valid C# or Visual Basic identifiers. If you do not (for example, you attempt to add a page to a module that has a period in its name), the generated class name for the page will not be a valid identifier and the code will not compile.

Add Page (with presenter) Next Steps

AddPageWithPresenterNextSteps.png

Last edited Nov 12, 2007 at 6:31 PM by siacomuzzi, version 5

Comments

No comments yet.