asp tutorials, asp.net tutorials, sample code, and Microsoft news from 15Seconds
Data Access  |   Troubleshooting  |   Security  |   Performance  |   ADSI  |   Upload  |   Email  |   Control Building  |   Component Building  |   Forms  |   XML  |   Web Services  |   ASP.NET  |   .NET Features  |   .NET 2.0  |   App Development  |   App Architecture  |   IIS  |   Wireless
 
Pioneering Active Server
 Power Search





Active News
15 Seconds Weekly Newsletter
• Complete Coverage
• Site Updates
• Upcoming Features

More Free Newsletters
Reference
News
Articles
Archive
Writers
Code Samples
Components
Tools
FAQ
Feedback
Books
Links
DL Archives
Community
Messageboard
List Servers
Mailing List
WebHosts
Consultants
Tech Jobs
15 Seconds
Home
Site Map
Press
Legal
Privacy Policy
internet.commerce














internet.com
IT
Developer
Internet News
Small Business
Personal Technology

Search internet.com
Advertise
Corporate Info
Newsletters
Tech Jobs
E-mail Offers

HardwareCentral
Compare products, prices, and stores at Hardware Central!

Customizing the VBCommenter PowerToy -- Cont'd
By Patrick Coelho


  • email this article to a colleague
  • suggest an article



    If the VBCommenter is so good, why do we need to modify it?

    The VBCommenter has a default code heading section that contains generic Xml markup. Although it contains a little more than C#, it could easily do more. The existing markup generated for a method looks something like this:

                ''' -------------------------------------------------------------

          ''' <summary>

          '''

          ''' </summary>

          ''' <param name="name"></param>

          ''' <remarks>

          ''' </remarks>

          ''' <history>

          '''   [logged in user]  mm/dd/yyyy  Created

          ''' </history>

          ''' -------------------------------------------------------------

    Function GetSetting(ByVal name As String) As String

    As consultants we work with many different clients. At Equarius, we have a coding standard where we display a copyright header which contains the client name at the top of each comment. It looks something like this:

    
    *****************************************************************
     Copyright [Current year] [client name]. All rights reserved.
    *****************************************************************
    
    
    We also have a history section to track code changes, which looks something like this:
    
    Revision History: 
    -----------------------------------------------------------------
      	Date		  Name			Description
    -----------------------------------------------------------------
     	mm/dd/yyyy	 [developer]		[free form text]
    
    
    We may also want to automate the inclusion of other Xml markup such as:
    
    	''' <exception cref="System.ApplicationException">
      	''' 	Thrown when... 
      	''' </exception>
    
    
    Or add more details to the Param node such as:
    
    	''' <param name="name">
      	''' 	[description goes here]. 
      	''' 	Value Type: <see cref="String" />	(System.String)
      	''' </param>
    
    
    Or add a returns section for functions
    
    	''' <returns><see cref="String" />(System.String)</returns>
    
    
    The automated markup I would like inserted for a method would look like this:

      ''' ***********************************************************

      ''' Copyright [year]  [client name]. All rights reserved.

      ''' ***********************************************************

      ''' Class.Method:     IConfigProvider.GetSetting

      ''' <summary>

      '''

      ''' </summary>

      ''' <param name="name">

      '''       [description goes here].

      '''       Value Type: <see cref="String" />   (System.String)

      ''' </param>

      ''' <param name="defaultValue">

      '''       [description goes here].

      '''       Value Type: <see cref="String" />   (System.String)

      ''' </param>

      ''' <exception cref="System.ApplicationException">

      '''       Thrown when...

      ''' </exception>

      ''' <returns><see cref="String" />(System.String)</returns>

      ''' <remarks><para><pre>

      ''' RevisionHistory:

      ''' -----------------------------------------------------------

      ''' Date        Name              Description

      ''' -----------------------------------------------------------

      ''' mm/dd/yyyy  [logged in user]  Initial Creation

      '''

      ''' </pre></para>

      ''' </remarks>

      ''' -----------------------------------------------------------    

         Function GetSetting(ByVal name As String) As String

    Note the use of the <see cref= "x" /> and <exception cref= "y" ></exception>. In both cases the "cref" attribute is used to create a link reference in the generated documentation to the type "crefed."

    Also notice the remarks node contains <para><pre> then the history followed by </pre></para>. "Para" is defined in the "Recommended Tags for Documentation Comments" in MSDN, while "pre" is an HTML markup tag that allows text to be rendered as is. Using the "pre" tag enables the table-like structure of the History section to be preserved when rendered as HTML in the generated documentation while keeping the section easy to update without the developer having to insert HTML markup.

    Over time we may want to change this structure, and for each client we will want to change the comment heading to reflect the new client name. It doesn't make sense to open the code, make the adjustments, and re-install the VBCommenter each time this needs to be updated. This is why I modified the VBCommenter so that much of this is configurable.

    1. Goals for this project:
        a. Make the comment headers configurable without having to rebuild the msi and uninstall/reinstall the add-on.
        b. Create a more robust comment header section.
         c. Add to the simple customizations that can be managed from within the IDE, specifically:
             1. Enable/disable copyright headers
             2. Set Client Name
             3. Enable/disable history block
         d. Enable rudimentary automation of NDoc from within the IDE.
         e. Enable Launching of the full NDoc GUI from within the IDE.
         f. Make as few code changes to the existing code base as possible, so that upgrading to the next version will go smoothly.

    2. Design decisions
         a. Maintain a configuration Xml, and Xslt file in a predefined location
             1. Update the setup utility so that it will create the following folder structure and copy the default documents: "VBCommenterConfig.xml" and "signatures.xslt" to it.
               ..\Microsoft.NET\Power Toys For Visual Studio 2003\VBCommenter\Resources
             2. The existence and format of these files are dictated by existing code structures.

    Overview of the code

    The VBCommenter project is made up of the following:

    /templates
    default-autoinsert.xslt
    - An Xslt style sheet that creates the header section based off an in memory xml representation of the method signature.

    Configuration.vb
    - Contains classes and interfaces that enable reading and writing to a configuration. In the current implementation the configuration is read from and written to the registry. There is some evidence of an earlier version that did use an Xml file.

    Connect.vb
    - This contains the classes, methods, and interfaces used to interact with the development environment.

    frmSettings.vb
    - A windows form that is launched when the user selects "Tools" --> "VBCommenter Options", it enables the user to enable or disable the following:

    • Creation of the Xml document file with each build.
    • Auto insertion of Xml comments
    • Auto insertion of the history section with the Xml comments.
    It also enables the developer to select from: '@, ', or ''' as the character sequence needed to generate the Xml comment section.

    Template.vb
    - This contains the classes and methods that gather information about the environment and the construct signature; it builds an xml document containing all these.

    TextInsertion.vb
    - This is the class that monitors keystrokes and document position, and handles the writing of each line of the comment section.

    Utils.vb
    - Contains several utility functions including the function that applies an Xslt style sheet to the Xml document containing all the meta data about the construct and its environment.

    VBCommenter.vb
    - This contains methods that determine if a header should be written, calls the appropriate methods in Template, TextInsertion, and Utils. It also receives the result from the Xsl transform handled in Utils and does further clean-up of the text prior to sending it to the page.

    XMLWriter.vb
    - Contains the methods used to build the in memory Xml document containing the signature metadata.

    We will touch code in only the following files:

    Configuration.vb - will add a few new keys to store and retrieve.

    frmSettings.vb - will add the following to this UI

    • CheckBox Add Copyright section
    • Textbox setClientName
    • OpenFileDialog to help set, retrieve, and store the path to the NDocGui.exe and the NDocConsole.exe
    • ListBox to add and remove dll names to (NDoc needs to know the path's to the dll that will be included in the documentation.)
    • Run button to execute the command line call to NDocConsole.exe
    Template.vb - will modify a few lines so that it first attempts to load configuration data from the file we write to the hard drive, before looking in the registry.

    Utils.vb - will modify the ApplyXSLTransformation method call so that it can accept an XsltArgumentlist (used for passing parameters to an Xslt)

    We will be creating two new files:

    • VBCommenterConfig.xml
    • signatures.xslt

    Configuration.vb

    The configuration class contains predefined keys and read write properties that enable storing and retrieving data to and from the registry We will be adding three new keys (see Figure: Configuration keys lines 26 -28):

    • keyClientNameForHeader
    • keyNDocGUIPath
    • keyNDocConsolePath
    And the corresponding properties (see Figure: Configuration Properties)

    This will enable us to retrieve and set these values from "frmSettings.vb.'

    << Introduction •       • frmSettings.vb >>

  • Other Articles
    Feb 23, 2005 - My Feature in Visual Basic 2005
    In this article, Thiru Thangarathinam demonstrates the different classes and features available through the My namespace. By providing a speed-dial that allows you to more quickly and effectively utilize .NET framework functionalities in your application, the My feature provides huge productivity improvements for .NET developers.
    [Read This Article]  [Top]
    Oct 6, 2004 - Creating Triggers Using Managed Code in SQL Server 2005
    Thiru Thangarathinam discusses taking advantage of the integation between the .NET CLR and SQL Server 2005 in order to do things like create triggers using managed code.
    [Read This Article]  [Top]
    Sep 8, 2004 - Custom Object Data Binding with .NET
    Developers often use brute force coding to marshal data between the GUI and application objects. In this article, Luther Stanton explains how to use .NET's out-of-the box data-binding functionality to make this job much easier.
    [Read This Article]  [Top]
    Aug 17, 2004 - The Perfect Service - Part 2
    Ambrose Little provides the complete source code for his 'Perfect Service' and explains how the .NET Service Manager enables features such as drag-n-drop deployment.
    [Read This Article]  [Top]
    Aug 12, 2004 - Middle-Tier Hosting: Enterprise Services, IIS, DCOM, Web Services, and Remoting
    There is broad-reaching debate about remoting, Web services, Enterprise Services, and DCOM. In short, it is a debate about the best technology to use when implementing client/server communication in .NET. Rocky Lhotka shares his thoughts on the issue while offering clear explanations of basic application architecture terminology.
    [Read This Article]  [Top]
    Jul 21, 2004 - COM Interop Exposed
    This article provides and excellent foundation for COM Interop. It reviews COM's background, explains how VB6 interacts with COM, and then shows how to design .NET components to smoothly interact with COM.
    [Read This Article]  [Top]
    Jun 24, 2004 - The Perfect Service - Part 1
    The first article in this two-part series shows how to get Ambrose Little's .NET Service Manager running and then how to add plug-n-play services to it using drag-n-drop or XCOPY.
    [Read This Article]  [Top]
    May 25, 2004 - Generics In-Depth
    Although generics are extremely useful, they also seem to have a certain mystique that cannot be readily explained. This article hopes to remove that aura of mystery by showing just how easy it is to use generics and how useful they can be in many common situations.
    [Read This Article]  [Top]
    May 11, 2004 - SharePoint Security and .NET Impersonation
    When implementing custom components that require access to restricted resources, implicit impersonation must be used. Jay Nathan shows how to create a class that makes using .NET Impersonation a snap.
    [Read This Article]  [Top]
    Mar 23, 2004 - Exploiting .NET's Advanced Deployment Features
    Tony Arslan shows how to use VS .NET's custom deployment feature to create configuration files on the target machine during installation.
    [Read This Article]  [Top]
    Mailing List
    Want to receive email when the next article is published? Just Click Here to sign up.

    Support the Active Server Industry