Using Iron Speed Designer as a Code Patterns Repository

Iron Speed MVP Gil Givati demonstrates how to teach Iron Speed Designer your favorite code snippets.
- Gil Givati, CEO of Efficens Software Ltd.

January 4, 2006
Iron Speed Designer V4.1

Background

When I started using Iron Speed Designer a few years back, I had to rely on my memory when customizing applications in order to remember the locations of common code snippets in my projects. Then came the Code Customization Wizard with a collection of over 90 code snippets, contributed by the global community of the Iron Speed Designer users world-wide. Looking at the architecture of the Code Customization Wizard snippets reveals the old saying "you can't teach an old dog new tricks" is irrelevant in our case. This article will give you the tools to teach Iron Speed Designer your favorite code snippets. As usual, when beginning to learn a new aspect of software programming, the first tutorial covers the famous greeting "Hello World". Our goal in this article is to create a code snippet that will replace text in the page (literal, value of text boxes, etc.) with "Hello World".

Our customized code will eventually be part of the Prerender method in the Record control and will change the text attribute of the literal in the following way.

FieldName.Text = "Hello World"

Each code customization snippet includes two components: documentation in HTML format and the code snippet itself in an XML document. These files (named CodeSnippetName.htm or .xml) are found under your Iron Speed Designer's installation folder, e.g.:

...\Code Customizations\group name

The best way to create your own code snippet is to copy an existing snippet and modify the copied files. In the documentation itself (the HTML file), you usually include the description of your code snippet, a description of the process needed to apply this snippet, on which types of pages it applies and other comments. Since this an HTML file, you can also use your own information as you'd like.

The Code Customization Template

The code snippet template itself is stored in an XML file. This file includes several tags that we will now cover. The first important part in the XML document is the <Substitutions> part. This is where you define the different variables that will be replaced when used in the Code Customization Wizard. You will later on see that variables in the code template itself are written as ${parameter name}. Each variable is written in the following structure:

<Variable>
    <Name>Record Control Class</Name>
    <Description>
    Select the record control where this customization will be inserted
    </Description>
    <Type>RecordControlClass</Type>
</Variable>

The variable Name is the name as it appears in the code snippet itself and will also be shown in the list of variables to be replaced in the Code Customization Wizard. Description is the prompt displayed in the Code Customization Wizard to explain the meaning of this variable. Last is the variable Type, including:

  • Control - which will result in a drop down of all controls in the page

  • TableName - which will result in a drop down of all tables in the database

  • FieldName - which will result in a drop down of all fields in the selected table

  • TableControlClass - which will list all table control classes in the page

  • RecordControlClass - which will list all record control classes in the page

  • RecordControl - which will list all controls in a selected record control
You have no limit as to the number of variables you can use in your code customization snippet.

For our example, I will use two variables: ”My Record Control” and ”My Control”. Their definition will look like the following:

<Substitutions>
    <Variable>
        <Name>My Record Control</Name>
        <Description>
        Select the record control where this customization will be inserted
        </Description>
        <Type>RecordControlClass</Type>
    </Variable>
    <Variable>
        <Name>My Control</Name>
        <Description>Select the field whose value needs to be set.</Description>
        <Type>Control</Type>
    </Variable>
</Substitutions>

You can see that "My Record Control" is a record control class and "My Control" is the control whose text attribute value is being set.

Now that we've defined our variables, we can continue and actually implement the code snippet. The code snippet itself will be included in <Customizations> part of the XML file.

The <Customizations> part specifies where the code should be inserted using the <Class> tags. Some of the values for this tag are:

  • DataAccessClass
  • RecordControl
  • Page
  • TableControl
  • SQLAccessClass
After the Class tag, we define the type of code inserted. I usually use "sub" since it's either a new method or code that goes into an existing method. For our example, the code customizations section will look like:

<Customizations>
    <Code>
        <Class>RecordControl</Class>
        <Type>Sub</Type>
        <Content>
        <![CDATA[
''' <summary>
''' Set the text property of a control to "hello world !"
''' </summary>
Private Sub RecordControl_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.PreRender
 
${My Control}.Text = "Hello World !"
 
End Sub
    ]]>
        </Content>
    </Code>
</Customizations>

Please note that we use the XML [CDATA] tag in order to include the code as is and not have the XML encode it for us when reading it from Iron Speed Designer. Another thing to note is our ability to write several pieces of code to match the different framework versions. You can find an example for that in the AJAX code customization.

Actually, that's the end of our journey. We have written our first code customization snippet and are ready to use it. To summarize, the complete XML file content will look like this:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<CodeCustomization>
   <Version>1.0</Version>
   <Type>Page</Type>
   <Description>
       <![CDATA[
        This will set "Hello World" into the text of the chosen field
       ]]>
   </Description>
   <FinishDescription>
     <![CDATA[
        You have now completed writing your first code customization
     ]]>
   </FinishDescription>
   <Substitutions>
     <Variable>
        <Name>My Record Control</Name>
        <Description>
        Select the record control where this customization will be inserted
        </Description>
       <Type>RecordControlClass</Type>
     </Variable>
     <Variable>
      <Name>My Control</Name>
      <Description<Select the field whose value needs to be set.</Description>
      <Type>Control</Type>
     </Variable>
   </Substitutions>
   <Customizations>
     <Code>
      <Class>RecordControl</Class>
      <Type>Sub</Type>
      <Content>
     <![CDATA[
''' <summary>
''' Set the text property of a control to "hello world !"
''' </summary>
Private Sub RecordControl_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.PreRender
 
${My Control}.Text = "Hello World !"
End Sub
      ]]>
     </Content>
    </Code>
   </Customizations>
</CodeCustomization>

Now you are ready to make Iron Speed Designer a repository for all of your favorite code patterns.

About the Author

Gil Givati
CEO of Efficens Software Ltd.

Gil has been working with IT systems for the past 17 years from both the infrastructure side of applications and the development side of it. During these years he has served as a database systems team leader for one of the Israeli defense forces software units and Chief technology officer. Gil has also served as the products group manager and CTO in a software house that is representing Sybase Inc., iAnywhere Solutions, Information Builders and other companies. As part of his job he was required to take active part in systems design and deployment. For the past two years Gil has managed Efficens Software and while also taking active part in its projects and products activities.

Gil earned a BA in Business Management from the Derby University in the United Kingdom.

Contact the author.



  Privacy Statement