Learn how to enhance the developer experience of building enterprise templates by adding custom help topics, customizing the Visual Studio .NET Development environment, and more.
In Part 2 of this series of articles, you learned how to customize the enterprise templates to create a new template from which we can create a new project. In this part, we will see how to enhance the developer experience (while working with our custom template) by adding functionalities such as adding custom help topics, customizing the Visual Studio .NET Development environment, and so on.
Adding Custom Help Topics to CustomDistributedAppTemplate
In this section, we will see how to add custom help topics to our enterprise template. Custom help topics are very useful when we want to provide guidance to our development teams on how to use the enterprise template. Once these custom help topics are created, we can then easily make them available through the dynamic help window in the Visual Studi.NET IDE. To accomplish this, we need to go through following steps.
- Planning and preparing the help topics that you want to display through the dynamic window
- Creating dynamic help topic category for the new topic—A dynamic help topic category allows us to group related help topics together so that they are displayed together in the dynamic help window.
- Creating context keywords that point to the help topic
- Linking up the project elements with keywords
Plan and prepare the help topics
Before creating the help topics, we need to prepare the help topics that we want to display. These help topics are normally created as HTML files and then linked up to the actual context keywords. In our case, we will create the help topics for the data access SqlHelper class and save the help file in the directory C:\Projects\CustomDistributedAppTemplate\Help\SqlHelperClass.htm.
Creating dynamic help categories
When you bring up dynamic help window from VS.NET, by default, Visual Studio.NET displays a window that is somewhat similar to the following.
In the above window, if we display a separate category named Custom Distributed Application Template, it will be a lot easier for our development teams to find out information on how to use our template. To accomplish this, we need to create a new XML file named CustomHelp.xml that looks like the following.
<?xml version="1.0" encoding="utf-8" ?>
<!-- The following is a link to the Dynamic Help schema. -->
Title="Custom Distributed Application Template"
Then we will save the above file in the directory <Drive Name>:\Program Files\Microsoft Visual Studio .NET\Common7\IDE\HTML\XMLLinks\1033.
In the above LinkGroup node,
- ID attribute specifies an identifier for this new help topic category
- Title attribute specifies the name of the topic category to display in the dynamic help window
- Priority defines the relative priority for this help topic when compared with the other help topic categories
- Glyph node specifies the icon to display when the help topic is expanded or collapsed.
Creating context keywords that point to the help topic
Using the KItem element, we specify the keyword that we want to use for this topic. This keyword must already exist in Visual Studio.NET. In this case, we are using the keyword VS.SolutionExplorer to target the solution explorer.
<KItem Name="VS.SolutionExplorer" />
Introduction to Custom Distributed
The Context element is added as a child node to the DynamicHelp element. Finally, we specify the URL of the help topic using a LItem element. Here we also specify the LinkGroup attribute to indicate the link group in which to display our topic link. We can reference any of the five default link groups specified in context.xml as well as any new link groups that we define. In this case, we are referencing the LinkGroup named customhelp that we defined previously.
Now, if you create a new project using our enterprise template and bring up Dynamic Help window, you will see a new custom help topic named Custom Distributed Application Template, as shown below.
Clicking on the Introduction to Custom Distributed Application Template will take you to the help topic that is contained in the file CustomTemplate.htm.
Customizing the Development Environment
In this section, we will see how to customize the development environment so that the developers don't have to spend trying to determine which options to use.
Setting default constraint for toolbox items
In this section, we will see how to set default property value for the EventLog component. You might recall that in our application we always log exceptions or informational messages using a specific event source. This is very handy because we can use the event source to uniquely identify all the exceptions that are logged from our application. We can enforce this in our application by creating a PropertyConstraint that pre-sets the event source property value of the EventLog component (that is available under the Toolbox->Components tab) to ExceptionManagerPublishedException. Once this is done, any time a developer tries to add the EventLog component to the application, the event source property will be automatically set to ExceptionManagerPublishedException and it will be read-only. We can accomplish this by adding the following entries to the CustomDistributedAppTemplate.tdl file.
As you can see from the above, we set the value of the READONLY element to 1 to prevent the event source property value from being modified. To verify this, if you drag and drop a EventLog component from the toolbox to the project, you will see that the event source property is set to ExceptionManagerPublishedException and it is read-only.
Disabling toolbox items
As we said in the beginning of this article, we want to standardize on SQL Server as the database of choice. Once we know that the database is SQL Server, we definitely want to take advantage of the high performance classes present in the System.Data.SqlClient namespace. Even though we have recommended the use of data access application block (that is included) as part of the development framework, sometimes the developers might want to add database related classes in their code. In that case, we don't want the developers to add the Oledb related classes (that are present in the namespace System.Data.Oledb) to the application. To prevent this, we will disable all of the oledb related toolbox items that are present under Toolbox->Data tab.
To perform this, we will open up the CustomDistributedAppTemplate.tdl file and add the following entries.
Now if you bring up the Data tab in toolbox, you will find that all the OleDb related components are disabled.
Putting It All Together
Now that we have constructed the different parts of the application, let us test our enterprise template by going to File->New Project and selecting Other Projects->Enterprise Template Projects. In the New Project dialog box, you will find CustomDistributedAppTemplate listed in the Templates pane.
In the above screenshot, when you enter a name for the project click OK, you will be prompted to enter the URL for the Web service.
Once you enter the URL and click OK, you will be prompted to enter the URL for the WebUI project as shown below.
Clicking OK on the above dialog box results in the template project being created and initialized. Once the project is created, if you bring up the solution explorer, you should see something similar to the following.
As you can see from the above screenshot, the template project, by default, provides developers with not only the desired application architecture, but also a clearly defined application development framework that comprises of a set of reusable components, architectural guidance, and best practices.
In this series of articles, we have seen how Enterprise Templates are a solid, cohesive part of an enterprise architecture plan. We have also had a detailed look at distributed application architecture as it relates to enterprise architecture and templates. We also discussed template policy files, Template Definition Language (TDL), application building blocks, customizing dynamic help, and so on. Specifically we discussed,
- How to use enterprise template projects to create application starting points by specifying an initial application structure, including any reusable or standard components and technologies, design documents, and models
- How to leverage the features provided by the enterprise templates for creating distributed applications
- How to create the application framework that consists of reusable components that can greatly simplify programming tasks by including pre-written code to handle procedures such as application management, exception handling techniques, security, and so on.
The initial investment in creating enterprise templates can go a long way towards reducing the per-project overhead. This assumes greater significance, especially when you anticipate that a particular class of applications will be developed several times in your organization.
Download Source Code: ETemplates.zip - 95 kb
About the Author
Thiru has six years of experience in architecting, designing, developing and implementing applications using Object Oriented Application development methodologies. He also possesses a thorough understanding of software life cycle (design, development and testing).
He is an expert with ASP.NET, .NET Framework, Visual C#.NET, Visual Basic.NET, ADO.NET, XML Web Services and .NET Remoting and holds MCAD for .NET, MCSD and MCP certifications.
Thiru has authored numerous books and articles. He can be reached at email@example.com.
# # #