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
International

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

    frmSettings.vb

    Update the form UI so that it looks like (Figure: VBCommenterSettings)

    We will also need to use the openFileDialog control

    The code for this form is pretty straight forward with the exception of launching NDoc.

    In the first scenario we launch the NDoc GUI. This is accomplished by first ensuring the user browses for the install location of NDocGui.exe

    The code to launch the application is contained in btnLaunchGUI_Click (see: Launch GUI)

    The second approach is to select dlls from the solution by clicking the add button.

    I use the Tag property of the Listbox to store a hashtable containing the full path to the dll, but only display the name within the view.

    When the user clicks run, the full paths are retrieved and the command line arguments are built into a string and passed to the NDocConsole.exe. (see: btnRunNDoc_Click)

    Template.vb

    Because of the way the code is written in 'Template.vb", in order to use a flat file for configuration, it must contain a pointer to a file path of an Xslt for each type of structure the xslt is designed to handle, see line 14 -15

    1.    Public Shared Function GetItemTypeTransformation(ByVal piTemplateType As TemplateTypesEnum, ByVal psItemType As String, ByRef pbInternalResource As Boolean) As String

     

    2.    Dim bOverridden As Boolean

    3.    Dim sRet As String  

    4.    Dim sTemplateType As String

    5.    Dim oConfigFile As Xml.XmlDocument

    6.    Dim oNode As Xml.XmlNode

    7.    Dim sNodeLocation As String

    8.    Dim sPathResourceDirectory, sSystemRoot As String

    9.     

    10.Const sConfigFile As String = "VBCommenterConfig.xml"

    11.Dim xConfig As XmlDocumentConfigImp

    12.:

    13.:

    14.sNodeLocation = "/config/templates/" + sTemplateType + "/" _

    15.+ psItemType

    16.oNode = oConfigFile.SelectSingleNode(sNodeLocation)

    17.bOverridden = False

    18.:

    19.:

    In this section the code tries to find a particular node within the config file. If it's not found the code will then get the information out of the registry. In order to plug into this we need to provide a path to the Xml config file and the config file must contain the relative path to the Xslt which contains the code needed to transform the node.

    The Xml configuration file will have to look like this:

    <?xml version="1.0" encoding="utf-8" ?>

    <config>

       <templates>

          <stub>

            <class>signatures.xslt</class>

            <delegate>signatures.xslt</delegate>

            <enum>signatures.xslt</enum>

            <function>signatures.xslt</function>

            <interface>signatures.xslt</interface>

            <namespace>signatures.xslt</namespace>

            <property>signatures.xslt</property>

            <struct>signatures.xslt</struct>

            <typedef>signatures.xslt</typedef>

            <variable>signatures.xslt</variable>

            <eventsdeclaration>signatures.xslt</eventsdeclaration>

            <event>signatures.xslt</event>

            <default>signatures.xslt</default>

         </stub>

       </templates>  

    </config>

    Notice that all the constructs point to the same Xslt file, "signatures.xslt." It would be possible to point each construct to its own Xslt file but that won't be necessary since it fairly straightforward to handle in one file.

    Next we will need to create our Xslt file. I've based my file on the "default-autoinsert.xslt" that is located in the templates sub directory of the project.

    (see autoinsert.xslt)

    Not the authors have inserted predefined constants that are replaced in code after the transform. This replacement is handled in VBCommenter.vb's GenXMLDocStub method. The following replacement characters have been defined:

    * [TAB]	Code Replacement: vbTab 
    * [CRLF]	Code Replacement: vbCRLF
    * [TRICK]	Code Replacement: ""
    * [CURSOR]	Code Replacement: "" - used only within "summary" to find a
    						position within the string.
    
    [TAB], [CRLF], and [TRICK] are not needed for generating the Xml Documentation but help with the positioning of rendered text and line breaks within the code text editor. Again, the replacement of these characters occurs after the Xsl Transform.

    So that we can customize the output from the style sheet we will need to accept the following input parameters to the style sheet. This is done by simply adding a few param statements at the top of the document (see Adding Params, lines 5-7)

    In order to pass param will need to modify Utils.vb to accept params (see apply transform)

    Note: line 364 we add the input parameter oXslArgumentsList so that xslt input parameters can be passed to this method

    Also note lines 390 and 392 where I changed "nothing" to this input XslArgumentlist

    One other place that will need to be updated is Template.vb's GetFilledXMLTemplateForCodeElement method. Here we will create the arguments list, add Current year, and retrieve from the configuration "client name" and "showHistory" flag. (see GetFilledXMLTemplateForCodeElement, 538-543)

    Next we need to take a look at the xml that the xslt stylesheet is designed to be used against, so that we can get a better handle on what data is available.

    Here is the Xml generated internal to the application for a subroutine:

    <xmldocinfo>

          <project>MyProject</project>

          <date>1/19/2004</date>

          <time>5:33:52 AM</time>

          <userid>coelhop</userid>

          <machinename>MyMachine</machinename>

          <name>Enumerations.subTest</name>

          <fullname>MySolution.Enumerations.subTest</fullname>

          <is-type value="false" />

          <code-element-type>function</code-element-type>

          <arguments>

                <argument>

                      <name>TestSub</name>

                      <typename>String</typename>

                      <typefullname>System.String</typefullname>

                      <byref>false</byref>

                </argument>

          </arguments>

    </xmldocinfo>

    A subroutine is defined as having "code-element-type= function" and no "return" node.

    The following is the Xml generated for a function:

    <xmldocinfo>

          <project>MyProject</project>

          <date>1/19/2004</date>

          <time>5:33:38 AM</time>

          <userid>coelhop</userid>

          <machinename>MyMachine</machinename>

          <name>Enumerations.strTest</name>

          <fullname>MySolution.Enumerations.strTest</fullname>

          <is-type value="false" />

          <code-element-type>function</code-element-type>

          <return>

                <returntypename>Int32</returntypename>

                <returntypefullname>System.Int32</returntypefullname>

          </return>

          <arguments>

                <argument>

                      <name>sTest</name>

                      <typename>String</typename>

                      <typefullname>System.String</typefullname>

                      <byref>false</byref>

                </argument>

          </arguments>

    </xmldocinfo>

    note the return node

    The following is Xml generated for a class:

    <xmldocinfo>

          <project>VBCommenter</project>

          <date>1/18/2004</date>

          <time>10:39:49 AM</time>

          <userid>coelhop</userid>

          <machinename>MyMachine</machinename>

          <name>Template</name>

          <fullname>VBCommenter.Template</fullname>

          <is-type value="true" />

          <code-element-type>class</code-element-type>

    </xmldocinfo>

    The Xml for the other contructs are very similar to those displayed here.

    In updating the Xslt, I decided to move the generation of the "header" to a named template so that it could act like a function and return a different string based on the input param "Client" (client name). So if no client name is supplied the default dashed line is returned, otherwise the copyright header is returned.

    I applied the same logic to the history section. It would be easy to apply this logic to the exception section also and make its presence configurable too ( I leave that as an exercise to the reader.)

    I added the exception tag to the comment section and also made the data returned for "param" and "return" more verbose so that it matched my requirements.

    The most important piece is having the VBCommentConfig.xml and at least one corresponding Xslt file at a predetermined path on the hard drive. Once you have the application reading from that source, it's relatively easy to totally transform the look and feel of the comment sections to your own needs with just a little xslt.

    Setup

    So far we've examined code commenting and the code changes made to make the VBCommenter add-on configurable, now lets go over setting it up:

    1. Download VBCommenter setup
    2. Ensure that all versions of Visual Studio are closed.
    3. Run "VBCommenterSetup.msi"
    4. ensure that "VBCommenterConfig.xml" and "signatures.xslt" are at: %systemroot%\Microsoft.NET\PowerToys for Visual Studio .NET 2003\VBCommenter\ Resources If these files are not there, try logging in as Administrator and running the installation again.
    5. goto sourceforge and download the web installer "NDocSetup.Exe"
    6. while connected to the internet, run "NDocSetup.Exe" this will download and install the latest version of NDoc (currently 1.2)

    Commenting Your Code

    1. Open Visual Studio
    2. Open an existing VB.NET project
    3. Add some comments by typing three apostrophe characters just before a code construct (e.g. class, function, property, etc.)
    4. Rebuild the project
    5. You should notice two new xml files with the same name as the project. One will be in the child directory or the project, this is a temp file. The real file will be located next to the dll in the bin directory. By default this file is rewritten everytime the project is built.

      Walk through running NDoc from within Visual Studio

    6. On the "standard toolbar" at the top locate "Tools" select this then "VBCommenter Options" the settings form will open. (see figure VBCommenterSettings)
    7. The first time this is launched you will need to tell it where the NDocConsole.exe application is.
    8. Ensure the checkbox "Use NDoc to Dynamically Generate MSDN style compiled help file", is checked.
    9. Click the Browse button a navigate to NDocConsole.exe. The default path is "Program Files\NDoc\bin\.net-1.1\NDocConsole.exe" this may be different on your machine.
    10. In the NDoc Procedures section click the "add" button this will launch a FileOpenDialog - use this to navigate to and select the dll for the project you just added comments to. (note: you can add several dll's from different projects and solutions)
    11. Click "Run"
    12. A FileSaveDialog will be launched asking where you want to save the output files to. Make you selection and click ok
    13. You should see a command prompt giving you feedback as the process runs. In a short while you will find in the folder you selected, several HTML pages (similar to "Tools --> Build Comment Web Pages...") to launch the website, double click on "index.htm"
    14. You should also find a file called "Documentation.chm" this is the compiled windows help file which is a standalone version of the same information.

    Walk through launching NDoc from within Visual Studio

    1. On the "standard toolbar" at the top locate "Tools" select this then "VBCommenter Options" the settings form will open. (see figure VBCommenterSettings)
    2. The first time this is launched you will need to tell it where the NDocGUI.exe application is.
    3. Ensure the checkbox "Use NDoc GUI", is checked.
    4. Click the Browse button a navigate to NDocGUI.exe. The default path is "Program Files\NDoc\bin\.net-1.1\NDocGui.exe" this may be different on your machine.
    5. Click Launch
    6. For more information on using NDoc see: http://ndoc.sourceforge.net/resources.html

    Conclusion

    Xml Code Commenting is a standard practice for C# developers, and now VB.NET developers have the same features at their disposal by using the VBCommenter. And with this updated configurable version of VBCommenter the developer can quickly automate the generation of professional looking interactive code documentation for multiple concurrent projects easily providing different customized comment headers, unique to each client.

    About the Author

    Patrick Coelho is a consultant for Equarius in Bellevue, WA. He specializes in .NET Web Service and ASP.NET development for EAI and B2B solutions. He has been developing ASP.NET C# and VB.NET applications since Visual Studio's beta 1 release and has co-authored 5 .Net books since 2001.

    Patrick holds a Bachelors of Science degree in Computer Software Systems from the University of Washington and the following Microsoft Certifications: MCP, MCAD (.NET), MCSD (.NET).

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

    Rate This Article

  • 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



    JupiterOnlineMedia

    internet.comearthweb.comDevx.commediabistro.comGraphics.com

    Search:

    Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

    Jupitermedia Corporate Info


    Legal Notices, Licensing, Reprints, & Permissions, Privacy Policy.

    Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers