BrainDump
  Home arrow BrainDump arrow Page 5 - Build a Domain Specific Language with DSL ...
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Dedicated Servers 
Moblin 
JMSL Numerical Library 
Windows Web Hosting
 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
BRAINDUMP

Build a Domain Specific Language with DSL Tools concluded
By: MSDN Virtual Labs
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 5
    2006-01-26

    Table of Contents:
  • Build a Domain Specific Language with DSL Tools concluded
  • Add a New Property
  • Introduce notation for the new property
  • Build a Business Entity Model with your new Designer
  • Generate a HTML report of your Model with your new Designer
  • Generate a HTML report of your Model with your new Designer

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Build a Domain Specific Language with DSL Tools concluded - Generate a HTML report of your Model with your new Designer


    (Page 5 of 6 )

    Now that we have built a sample business entity diagram, you may be wondering what you can do with it. In this task we’ll demonstrate how to use the text generation functionality included with the DSL toolkit to generate artifacts from our model. Text generation works via template files, which contain both templatized text to be generated, and logic which controls how that generation happens. Let’s look at an example which takes a .biz file as input, and generates an HTML report over the domain defined in that file.

    1. Right-click on the BizEntityDebugging project in the Solution Explorer, and choose Add->Existing Item… from the context menu.

    2. Set the Files of Type: filter to All Files.
    3. Type c:\dsl\BizEntity.ReportTemplate into the File name: box, and press Add.
    4. Double-click on the newly added BizEntity.ReportTemplate file in the Solution Explorer to open it in the text editor  (you may want to close the Toolbox window at this point to give the text editor more room). We will examine the details of this file to see how code generation works.
    5. The first three lines, shown below, set up some parameters for the code generator, we won’t concern ourselves with the details of those here:

      <#@ template inherits="Microsoft. VisualStudio.TextTemplating.
           VSHost.ModelingText Transformation"#>
      <#@ output extension=".htm" #>
      <#@ er processor="BizEntity DirectiveProcessor"
       requires="fileName='Empty.
      biz'" #>

    6. The next five lines are standard HTML, these will be generated to the output file as static header text:

      <html>
      <body>
      <h1>A report on the contents of Empty.biz</h1>
      <p>For this report to work…</p>
      <h2>Entities:</h2>

    7. Now things get interesting. Notice the <# and #> tags which delimit sections of the file. Logic which controls text generation in placed within these tags (if you are familiar with ASP pages, this is a similar idea). In this case, the logic is written in C#, but it may be written in Visual Basic .NET as well. To make clearer what’s going on, we’ve grayed out the text to be generated below so you can just focus on the control flow; if you are familiar with C#, you will notice that what’s left are two nested for each loops, the outer one over a collectio n called “Entities” and the inner one over a collection called “Attributes”. As you may have guessed, these collections contain elements instances from the domain model.

      <#
          foreach ( Entity e in this.ER.Entities )
          {
      #>
          <h3><#=e.Name#></h3>
          <p>Kind: <#=e.Kind#></p>
       <#=e.Kind#></p>
      <#
            foreach ( Attribute a in e.Attributes )
            {
      #>
          <p>Attribute: <#=a.Name#>
      <#
            }
      #>
      <#
          }
      #>
    8. Now let’s look at the same section of the file, but focus on the generated text. As in the static header, these lines are HTML, except for the <#= #> tags, which indicate parameters that will be filled in by values from the domain model during generation. Note the use of the properties “Name” and “Kind” to indicate which values from the domain model will be used. Also note the use of the foreach loop iteration variables  “e” and “a” to indicate which Entity and Attribute instances are used in the parameterization (these have been bolded for emphasis).

      <#
          foreach ( Entity e in this.ER.Entities )
          {
      #>

          <h3><#=e.Name#></h3>
          <p>Kind: <#=e.Kind#></p>
      <#
            foreach ( Attribute a in e.Attributes )
            {
      #>
          <p>Attribute: <#=a.Name#>
      <#
            }
      #>
      <#
          }
      #>
    9. Next, let’s run the template. Click on the BizEntity.ReportTemplate file in the Solution Explorer.
    10. In the Properties window, enter the value TextTemplatingFileGenerator for the Custom Tool property, and press Enter.


    11. Notice that a “+” appears next to the BizEntity.ReportTemplate file in the Solution Explorer. Click on this to reveal the generated file, BizEntity.htm. Right-click on this file and choose View in Browser from the context menu to see it rendered in Internet Explorer.


    12. Notice that the Entities and Attributes defined in the business entity diagram appear in this report. Due to the interaction logic in the template, if we were to add additional Entities or Attributes, and re-run text generation, those additional items would appear in the report.
    13. Close the BizEntity.htm file

    More BrainDump Articles
    More By MSDN Virtual Labs


       · We hope you found this article from MSDN Labs to be entertaining and informative....
       · I think this is useful work,good done!Only one thing... where can I find the file...
       · Click on the "author bio" and you will find a link that will take you to the MSDN...
       · thanks for reply, sorry i didnt find any link like "author bio" , can you give me...
     

    BRAINDUMP ARTICLES

    - XAML Brushes and Silverlight
    - Silverlight and XAML Basics
    - Immortal XP
    - XAML Basics
    - Microsoft Surface
    - Making Your First Active X Control in Visual...
    - Codes and Packages in Microsoft Project 2007
    - Windows 7: Rumors and Demos
    - XP SP3 Why Me?
    - Breaking Up Your Work in Microsoft Project
    - Breaking Work into Task-Sized Chunks
    - Putting Microsoft`s Worldwide Telescope Unde...
    - Handling Multiple Contracts with Indigo
    - Cleaning Out Your Data in XP
    - Multiple Service Contracts and Indigo





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway