in

dotnet.org.za

South African .NET Developer Portal

Adam Heunis tech talk

Software mostly, but other techie stuff as well. I primarily use Notepad, Visual Studio, the Command Prompt, XmlSpy, SQL Server, MySQL and Photoshop. I speak
C# (incl. OO), XML, XSL, ASP.NET, VB.NET, VB6, SQL, UML and XForms.

April 2005 - Posts

  • Improve XSLT transform performance with XPathDocument

    Provided you know XSL, there is hardly an easier way to transfrom xml to more xml, text or html than using XSLT. If you're doing this in .NET there are some things that you should keep in mind:

    • Don't use XmlDocument as the source of an XSLT transformation; rather use XPathDocument. Basically you can't do much with XPathDocument other than calling its CreateNavigator (implements IXPathNavigable.CreateNavigator) method. This method will return a read-only cursor model based on the XPath data model. The key here being "read-only", thus making it lighter and quicker for reading (or transforming). Using XPathDocument rather than XmlDocument will also avoid another "sibling axis" issue described in Q325689.
    • XmlDataDocument inherits from XmlDocument, so avoid using this as your source as well.
    • Avoid using msxsl:script in server-side (ASP.NET) transforms. Rather cache the transformations produced by the msxsl:script and reuse.

    This will allow you to transform XML quicker than Bryan Habana can cross the tryline!!

    If you don't know how to do XSLT transformations in .NET , the GotDotNet boys explain it really well (with examples) at "How Do I...Apply an XSL Transformation to XML?".

    This post references:

    Posted Apr 25 2005, 03:03 PM by attie with 4 comment(s)
    Filed under: , ,
  • Software Soap Opera

    Linus Torvalds, former champion of the common man, has fallen from grace in almost Soap Opera style. Name calling and toy throwing are the order of the day now at Open Source Central.

    This article says it all. The legal issues surrounding reverse engineering are very interesting.

  • How to blog without fear

    I wrote this post about the "private life - working life" issues of blogging on my personal blog. Since we are all bloggers, I thought it might be of some interest. There is also some stuff about the Electronic Frontier Foundation (EFF) guidelines for bloggers to this end.

  • Why AJAX? The benefits of AJAX explained.

    While reading the comments on Armand's AJAX Wrapper DLL post, I got the impression that readers weren't quite sure about the benefits of AJAX.

    AJAX has two huge benefits:

    1. Speed and invisibility (ala smart client) makes for a very slick user experience.
    2. The smaller server resources footprint helps server scalability (seriously!).

    I'll explain. If you post using AJAX, only the data (or parameters) that the server function requires is posted. In a login scenario, only the username and password strings (100 bytes maybe) are sent to the server and only a boolean value (1 byte) is returned. This means that only 101 bytes (excluding network handshaking traffic) is sent & received. For this same functionality using ASP.NET all the state data is pushed and the whole page is returned. In a conservative case, when a page might be 20k, you will literally produce 99.5% less traffic when using AJAX.

    Further more; when using AJAX your web server and or db server (or whatever your config is) does not have to do any processing other than running the called function and returning the return value. No page load events, no xsl transform etc. This can have a huge impact in an enterprise environment. Case in point: While working on a huge financial services CRM package, we were able to improve usage from 150 users/minute to 250 users/minute with an AJAX implementation.

    The one thing that you do have to be careful about is security. Without proper security, you're left wide open (much more than with ASP.NET). Currently there is no security in the .NET wrapper Armand mentions. But in a response to one of my comments, Michael Schwarz indicated that this is something on his roadmap.

    Oh yes and AJAX is absolutely disconnected. In the same way as a normal web page or a smart client, AJAX has no idea of state.

    My final thought: Using AJAX you can have the flexibilty of a browser, but the slickness and reduced network traffic of a smart client. Highly recommended.

    My final final thought: Be sure to let Michael Schwarz know that you would love to see his very useful AJAX .NET Wrapper as an open source project.

  • .NET and MySQL myths exploded

    Profesionally I almost exclusively use SQL Server, but for my own stuff I've been using MySQL for a while now. I started on MySQL because it is "free" (under a GPL license) and because of their support to the open source community and the No Software Patents organisation. Whenever I mention this to .NET/SQL developers they always assume it is only because of ethical or cost reasons. No Sir!

    Myth 1 "MySQL's performance sucks" exploded:

    MySQL's performance is fabulous. It compares very well with Oracle & SQL Server and in some cases even better. "No way" I hear you say. Check out these independent benchmark tests by eWeek.com and weep. I'll sumise some of the results:

    • "Of the five databases we tested, only Oracle9i and MySQL were able to run our Nile application as originally written for 8 hours without problems."
    • "The Oracle and MySQL drivers had the best combination of a complete JDBC feature set and stability."
    • "SQL Server and MySQL were the easiest to tune, and Oracle9i was the most difficult because it has so many separate memory caches that can be adjusted."

    Also take a look at their very impressive customer list. Here are some of the names: Yahoo!, Google, Deutsche Post (largest postal service on the globe), NASA, US Census, Intel, Dell, Apple, Cap Gemini Ernst & Young, Wikipedia, AP, Toyota South Africa, Yahama etc. These guys won't be satisfied with bad performance!

    Myth 2 "MySQL is not for .NET" exploded:

    There is a perception in the .NET (if not software) community that MySQL is only for PHP. Nothing could be further from the truth. The boys at MySQL (a German company - so you know you're gonna get quality), have for a while been developing a ADO.NET Connector. Connector/Net is a secure, high-performance, fully managed ADO.NET driver written in C#. I've been using Connector/Net (not the latest version, though) for ages now on my Eastern Cape tourism site and I've not had any problems with it.

    You can download MySQL's Connector/Net 1.0 (under a GPL license) from here.

    Myth 3 "Administering MySQL sucks" exploded:

    Another bugbear is that Administering MySQL is a pain in the behind. In my opinion, this is partly true. Most PHP guys use a freebie called MyPHPAdmin. This is a web-based admin tool that is quite powerful and flexible. Personally though, I don't use this unless I absolutely have to. I much prefer Navicat. This is a fantastic tool. It has most things Enterprise Manager/Query Analyzer has. In some cases, especially data transfer and backup/restore, it is better than the MS tools. The only downside to Navicat is that is costs something (I think it was $99), but to my mind this is still very affordable.

    That is my 2 cents on .NET and MySQL.

    It would be good to hear what the panel says :o).

  • Don't do it, Linus!

    There is a battle of wills a going on at the moment. It is an age old battle between those who want to empower the people and those who want to empower themselves. You probably already know whose side I'm on!

    This time the battle is for the soul of Linus Torvalds. Linus, for those of you who don't know, is the viking who started Linux. More importantly though, he is probably the biggest open source advocate on the face of the planet.

    Anyway Linus has been using open sourced Bitkeeper as his source control for time. The trouble is that the makers of Bitkeeper have now decided that its open source policy is no longer part of their future. Linus now has a huge decision to make: does he continue subscribing to the ideals of open source and redo all his source code OR does he use a commercially licensed copy of Bitkeeper and alienate himself from a community that he partly founded.

    The software community waits... and waits...

  • Telkom name change

    Could it be true?

  • IT salaries in South Africa

    The company (huge global company) I'm consulting for is looking at outsourcing some big projects in 2006/2007. At this stage they're looking primarily at an Indian company they've used before, but the last time round they weren't too happy with the quality of the software. So with that in mind and in the hope of sounding clever I was wondering what South African IT people get paid.

    Feedback is very welcome, but I'll only be accepting anon feedback. Otherwise figures will be inflated :). If you post feedback, please state what job you do (broadly speaking); your salary or rate; whether you're contracting or permie and where in SA you work.

    Also it would be great if anyone knows of a site that has more info on this.

  • To refactor or not to refactor?

    In the world of Extreme Programming (XP), refactoring has become the new buzzword. Business usually doesn't quite understand what it means and, in my experience, sees it as having little or no benefit. As a software consultant, I have to say that in most cases refactoring has a very important role to play. Although most of the benefits are medium to long term (maintainability & extensibility), there are short term benefits (usually performance) as well.

    I'm currently refactoring a big project that we finished a couple of weeks ago. The improvements I have already made to the code (my own code and others') have improved the application dramatically. Not only is the performance up by about 300% (my guestimate), but the code makes so much more sense as well; thus improving maintainibility and extensibility. This should make business happy as well, because they will save on any future development or integration of the code. It is only really when an application really will never be touched again and performance is acceptable that refactoring becomes redundant. And how often does that happen?

    By the way refactoring is not bug fixing or exposing bad code (although this is often a side effect). It is much more to do with the fact that both business and development have a much better idea of everything about the application (incl. use cases, business requirements etc). Amongst other things, business requirements often change over the course of a project. Refactoring allows developers to re adapt and optimise the code with this in mind. Refactoring is integral to the whole principle of iterative development.

  • First South African podcast?

    My wife and I have just made our first episode of The Attie & Lené show. As far as we know, this is the first South African podcast.

    For those of you who don't know what a podcast is; it is essentially a radio show stored as an MP3 on a server somewhere. Listeners then either download/stream or subscribe (in technical sense) with 3rd-party software (see below) and listen at there own leisure. Most of the 3rd-party tools also integrate in some way with iTunes. Personally I think you could also see it as an audio blog.

    It started off in the US as a counter to the commercial radio stations in the US. The guys felt that since all the radio stations were bought up by only a few big players, they all started sounding excactly the same. Apperantly it is huge over there and interest in the UK is also growing rapidly, especially since the BBC did a programme on it.

    Check out Pod101 if you want to know more. iPodder is a good open source application that manages your subscriptions..

  • Resharper from Jetbrains

    Resharper is a very useful Visual Studio.NET add-in by Jetbrains. It has a lot of really neat features that I suppose Visual Studio should have, but doesn't. It integrates quite well with VS. The main areas are:

    • Error highlighting
    • Error quick fixes
    • Refactoring

    But it has other useful stuff as well. A handy utility that removes all your unused references and "using" statements with a single click, for instance. Its only huge downside is that it costs $99 per developer. There is a trial version available though.

    Posted Apr 04 2005, 07:08 PM by attie with 4 comment(s)
    Filed under:
  • Numerical iteration in XSL

    Have you ever wondered how to iterate a set number of times in XSL? While it is easy to "walk" a nodelist using xsl:for-each or xsl:template, it is a bit more tricky to iterate a set number of times (the "for" statement in C#). Here is what you do:

    <?xml version="1.0"?>
    <xsl:stylesheet 
    version="1.0" xmlns:xsl="...">
    <xsl:template 
    match="/">
     <xsl:call-template 
    name="iterator">
      <xsl:with-param 
    name="LastNo">10</xsl:with-param>
     <
    /xsl:call-template>
    <
    /xsl:template>
    <xsl:template 
    name="iterator">
     <xsl:param 
    name="LastNo"/>
     <xsl:param 
    name="i" select="0"/>
     <xsl:value-of 
    select="$i"/>
     <xsl:if 
    test="$i &lt; $LastNo">
      <xsl:call-template 
    name="iterator">
       <xsl:with-param 
    name="LastNo" select="$LastNo"/>
       <xsl:with-param 
    name="i" select="$i + 1"/>
      <
    /xsl:call-template>  
     <
    /xsl:if>
    <
    /xsl:template>
    <
    /xsl:stylesheet>

    This will iterate through the "iterator" template 10 (derived from the "LastNo" variable) times.

    Posted Apr 03 2005, 06:06 AM by attie with 2 comment(s)
    Filed under:
  • Complicated configuration settings with a custom ConfigSectionHandler

    Most of the time when you need configuration settings for an application, they have to be simple name/value pairs. For instance: connection strings, timeouts etc. Occasionally though you might want more complicated or hierarchical configuration settings. For instance: a complicated and/or conditional route that an MSMQ message should take. This is when you can use a custom Configuration Section Handler. Building a custom configsectionhandler is easier than you'd think. Essentially it requires 4 easy steps:

    1. adding the configuration data as xml to the .config (app or web) file.
    2. implementing a IConfigurationSectionHandler (part of System.Configuration) in a new class.
    3. linking 1 and 2
    4. retrieving the configuration data (as xml).

    You can go further if you want by serializing the configuration data into an object, but this is not a requirement. As I don't want to confuse the issue, I'll explain how to do this in a future post.

    So lets get cracking:

    First of all you add the configuration data into the config xml. Lets continue along the MSMQ example.

    <MessageRoute>
        server="vectorsoft-web1" queueName="web_in"/>
        server="vectorsoft-bo1" queueName="bo_in"/>
        status="1">        
            server="vectorsoft-bo1" queueName="bo_out"/>
        <
    /condition>
        status="2">
            server="vectorsoft-data1" queueName="data_in"/>
            server="vectorsoft-data1" queueName="data_out"/>
            server="vectorsoft-bo1" queueName="bo_out"/>
        <
    /condition>    
        server="vectorsoft-web1" queueName="web_out"/>
    <
    /MessageRoute>

    Don't worry too much about the actual xml, as long as its a complicated/hierarchical format it serves the purpose.

    Next, a very simple class that extracts the config data as a node. This class implements the IConfigurationSectionHandler interface.

    using System.Configuration;
    using System.Xml;

    namespace Vectorsoft.ConfigSectionHandlerDemo
    {
        
    public class SectionHandler : IConfigurationSectionHandler
        {
            
    public SectionHandler() {}
            
    public object Create(object parent, object configContext, XmlNode section)
            {
                
    return section;
            }
        }
    }

    You will see that the create method returns an object. With this in mind you can return a serialized class instead of a node. This create method is the one to modify if you want to do this. I'll show you this in a future post, but as I said before I don't want to confuse the issue, so we're just going to return all the data as a node. Because it is xml this is entirely feasable and easy.

    Then you link up the config data to the appropriate handler.

    <configSections>
     

    ="MessageRoute" type="ConfigSectionHandlerDemo.SectionHandler, ConfigSectionHandlerDemo" />
    <
    /configSections>


    As you can see this is quite simple. You'll see the name attribute is the same as the config data's element name. The type attribute consists of the fully qualified class name and the assembly name. The configSections element sits in the configuration (root) element.

    Now all that is left is referencing the attributes and/or elements in the node. To do this is a simple case of typecasting the returned object into a XmlNode or XmlElement (my preference) and then using standard xml methods to retrieve the element/attribute you're looking for. Like so:

    XmlElement personEle = ConfigurationSettings.GetConfig("MessageRoute") as XmlElement;
    Console.Write(personEle.GetAttribute("firstname"));

    And that is it!

    Posted Apr 01 2005, 01:24 AM by attie with 5 comment(s)
    Filed under:
Powered by Community Server (Commercial Edition), by Telligent Systems