Archives

Archives / 2005
  • Equivalent of sys* tables of SQL Server in Access

    When working with SQL Server it is easy to get access to database metadata like tables, stored procedures etc, by using the sys* tables. I was doing some work with Access and wanted to do something similar, turns out that it is quite easy to do.

    Basically the OleDbCommand.GetOleDbSchemaTable() method allows you to get as much metadata you want about the DB.

    Pretty obscure but a God send when you really need it :)

  • Why do we get paid so much?

    I was just thinking today about why software developers are typically paid so much more than other people in similar kind of work. One reason might be because software companies generate more revenue per employee as compared with other industries.

    Construction or any other engineering discipline is as complex as software, but software is unique in the sense that building software is the easy part, this is very different from the other engg. disciplines where manufacturing is the hard part. Think of construction, It is such an immensely complex task that if you don't know how it's done you'd wonder how anything even stands up. Can you imagine if we had bugs in skyscrapers? But coming back to the point, it means that constructing a building is like building a piece of software with a quality level so high that maybe only NASA can achieve. Then why don't construction people get outrageously high salaries?

    The answer IMHO is standardization, the construction industry is so standardized and they have such well-defined patterns that although to a layman a building construction may look incredibly complex, to the builder it's just like putting Lego blocks together.

    So that means if the vision of software factories becomes a reality, it would mean that building software would require an architect who would design the system and then junior guys just use standard off the shelf components to build it. Nirvana. Yeah but not for us,[ :)] once that happens the cost of software goes down and hence so do our  pays [:)]

    So why is that the software industry has not yet mastered component based development, again IMHO these things take time, again look at construction, human beings have been building ever since they moved out of the caves, serious architecture and building techniques have taken thousands of years to be perfected, how old is our industry? about 50 years, so we have a long way to go before we reach the level of sophistication that the consstructuon industry has. Which means that we are safe atleast in our lifetimes. [:)]

    Let's speculate a bit more and try to see into the future, so what will be the software industry of the next generation, my guess is bio-tech. Bio-tech is in it's nascent stages just like software was in the 50's and the 60's, but in the next few decades it's going to make a huge huge impact on our lives. And you can be sure that IIT or MIT elite will be opting for bio-tech rather than computers in about 10-15 years.

  • Cool sites discovered using Spiderous

    Spiderous is a site that aggregates popular links from social bookmark managers like del.icio.us , spurl and furl
     
    Here are some great links I found today
     
    Tabs on your webpage using CSS
     
    Like to build your own systems, check out this article on advanced system building
     
    Color Scheme generator
     
    Free Menu designs using CSS
     
    Fade anything technique for web pages
     
    The state of the scripting universe
     
    A+ Freeware

  • ADO.Net connection pooling

    Connections are precious commodities, and writing code to minimize the stress on the server of having too many connections open concurrently will help with overall database performance. Fortunately, ADO.NET (like its predecessors) tries to help manage those connections with a facility called Connection Pooling. Connection Pooling is the process of managing connections as shared resources that can be doled out from a pool of recently used connections. Connection pooling takes advantage of the fact that many different parts of most applications require connections for a short amount of time as well as the fact that building and tearing down connections is an inherently expensive operation. Connection pooling is a method of reusing connections. The real magic occurs when connections are closed, because the pool hangs on to the connection for some short time (the pooling timeout) before actually closing the connection. If another connection is requested before that short amount of time has elapsed, it hands the open connection to the requestor. This saves the actual work of tearing down the connection and opening a new one. By utilizing connection pooling, you reduce the likelihood of making a round trip to the database only to find out that the database is out of connections. The connection pool reduces the time it takes to determine the out-of-connections state. In fact, with the connection pool, the additional requests can block to wait for a new connection to be available. This allows a machine to throttle its actual usage of the database so as not to swamp a particular database server with requests.

  • Load event gets fired on each call to ShowDialog()

    While chasing down one bug in my custom message box at codeproject I came acorss an interesting fact. If you use ShowDialog() to show your form then the Load event gets fired everytime. I've been using Winforms for such a long time and was surprised that I had never really come across this behaviour.

    It's not a bug, if you use reflector and take a look at Form.ShowDialog() you will see that the flag which is used to prevent Load event from getting fired more than once is disabled everytime ShowDialog() gets called.

  • A new approach to Web Forms

    Mike Roberts talks about a new approach to WebForms, he is the author of CruiseControl.Net a continuous integration software for .Net.

    Extract

    'What??' you may cry. 'You've stopped using ASP.NET??' No, I've just stopped using Web Forms. Web Forms are those .aspx files you write and their code behinds. They're also the things that use server controls, view state and other such components that make up most of .NET web apps. I'm still using the ASP.NET runtime in the form of an IHttpHandler. This is a much more lightweight way of developing web apps, similar to Java's Servlets.

    http://mikeroberts.thoughtworks.net/blog/archive/Tech/dotNet/GoodbyeWebForms.html


  • Spam Filter technology to fight AIDS

    Microsoft Research has pioneered promising new ways to combat one of humankind's most deadly viruses with advanced software typically used to analyze large computer databases and complex digital images, or to separate spam from legitimate e-mail.

  • Tidbit on VisualStyles in Windows Forms

    I wanted to implement theme support for my MessageBox component mentioned in the previous post, I came acorss this excellent post on how Application.EnableVisualStyles() works. So basically it uses the Activation Context API to specify that the v6.0 of common controls should be used.

    When I looked at the API, I found that you have to specify a manifest file to specify that information. Now where does that manifest file come from? So I fired up reflector and this is what I found. Below is the code for the method that creates the ActivationContext for your application.



    private bool EnsureActivateContextCreated()
    {
    bool flag1;
    lock (typeof(SafeNativeMethods.EnableThemingInScope))
    {
    if (!SafeNativeMethods.EnableThemingInScope.contextCreationSucceeded)
    {
    string text1 =
    null;
    FileIOPermission permission1 =
    new FileIOPermission(PermissionState.None);
    permission1.AllFiles = FileIOPermissionAccess.PathDiscovery;
    permission1.Assert();
    try
    {
    text1 =
    typeof(object).Assembly.Location;
    }
    finally
    {
    CodeAccessPermission.RevertAssert();
    }
    string text2 =
    null;
    string text3 =
    null;
    if (text1 != null)
    {
    text3 = Path.GetDirectoryName(text1);
    text2 = Path.Combine(text3,
    "XPThemes.manifest");
    }
    if ((text2 != null) && (text3 != null))
    {
    SafeNativeMethods.EnableThemingInScope.enableThemingActivationContext =
    new SafeNativeMethods.EnableThemingInScope.ACTCTX();
    SafeNativeMethods.EnableThemingInScope.enableThemingActivationContext.cbSize = Marshal.SizeOf(
    typeof(SafeNativeMethods.EnableThemingInScope.ACTCTX));
    SafeNativeMethods.EnableThemingInScope.enableThemingActivationContext.lpSource = text2;
    SafeNativeMethods.EnableThemingInScope.enableThemingActivationContext.lpAssemblyDirectory = text3;
    SafeNativeMethods.EnableThemingInScope.enableThemingActivationContext.dwFlags =
    4;
    SafeNativeMethods.EnableThemingInScope.hActCtx = SafeNativeMethods.EnableThemingInScope.CreateActCtx(
    ref SafeNativeMethods.EnableThemingInScope.enableThemingActivationContext);
    SafeNativeMethods.EnableThemingInScope.contextCreationSucceeded = SafeNativeMethods.EnableThemingInScope.hActCtx !=
    new IntPtr(-1);
    }
    }
    flag1 = SafeNativeMethods.EnableThemingInScope.contextCreationSucceeded;
    }
    return flag1;
    }

    So the manifest file is called XPThemes.manifest, the intresting thing was how the code determines the directory in which to find the file, the relevant line of code is

    text1 = typeof(object).Assembly.Location;

    Since object is defined in mscorlib.dll and that is present in the directory where .Net is installed
    the code can get the location where it can find XPThemes.manifest

    If you search for XPthemes.manifest it will be present in the folder where you installed the .Net runtime.





  • Tool for analyzing .Net assemblies

    NDepend analyses .NET assemblies of an application and generates design quality metrics. NDepend allows you to automatically measure the quality of a design in terms of its extensibility, reusability and maintainability to effectively manage and control the assemblies’ dependencies of your .NET applications. Moreover, NDepend helps you to get a thorough view of the topology of your application, at component at type and at member level.

    Check out the sample report they have on the site. Really cool indeed.

    http://smacchia.chez.tiscali.fr/NDepend.html

    It's been developed by the same guy who has written this excellent article on iterators in C# 2.0 that not only talks about iterators but also about some cool ways to use iterators in your applications.
    http://www.theserverside.net/articles/showarticle.tss?id=IteratorsWithC2


  • Richard Grimes has stopped writing on .Net

    I was just looking for the great workshop on Fusion written by Richard Grimes I saw on the front page of his site that he has stopped writing about .Net. That was quite odd considering that he has written some great articles and books on the subject and is a regular speaker in various events. Googling revealed that he has written an article in DDJ detailing his departure from .Net.

    You can read his thoughts on why he does not want to associate with .Net anymore here. You'll need to register to read the article.

  • Cool class of the day - ISerializationSurrogate

    I was doing some research in custom XML serializaton in .Net. The problem is the same as the O-R problem  for database persistence, the difference here is the level of support that .Net provides in helping with that serialization. I stumbled upon a great site for XML related information http://www.topxml.com and while going through some tutorials on that site came across this cool class called ISerializationSurrogate. You can read more about it here http://www.topxml.com/xmlserializer/surrogateselectors.asp

    Basically it allows you to move the serialization code away from the object being serialized. A class that implements this interface can act as a surrogate for the class that it serializes. So that's another hook you can use to customize your serialization.

  • del.icio.us

    A couple of days back i was looking for an online bookmark manager, i found some really good and free ones but the one that caught my eye was http://del.icio.us . It is a social bookmark manager, what that means is that when you add a new bookmark you can see what category other people have added that link in, you can then see other bookmarks in that category to discover new sites related to the one you are bookmarking. The best thing is that all these categories are available as RSS feeds, so you can subscribe to the feed for that category and whenever anyone adds a bookmark in that  category you get notified. Not only that you can subscibe to the most popular bookmarks in a paticular category.

    Here is the help that describes the RSS feeds that are available

    » del.icio.us offers you many ways to view your own and other people's bookmarks. Understanding how del.icio.us URLs work makes it easier to see exactly the bookmarks you want.
    » Every user has a unique homepage:
     del.icio.us/geoffrey
    » Tags also have their own pages:
     del.icio.us/tag/politics
    » You can filter bookmarks by user and tag together:
     del.icio.us/geoffrey/literature
    » This will show all bookmarks from user geoffrey tagged as 'literature'.
    » Use plus signs to combine multiple tags into a tag intersection:
     del.icio.us/tag/politics+france+history
    » This will display only bookmarks that have all three of the tags 'politics', 'france', and 'history'. This also works for user/tag combinations:
     del.icio.us/geoffrey/literature+english

     The interface is a bit spartan with almost no images at all. But the site is fully functional. I've already discovered some cool sites using this. It works in Firefox as well as IE and other browsers via a bookmarklet, pretty easy to setup. This is one cool concept.

  • What a wierd bug or feature?

    A couple of days back i was working on an app, when i came across this problem. So the thing is that there are two events in DataTable, one is called OnRowChanging and the other is called OnRowChanged. Well i figured since i wanted to access the newly added row in the table OnRowChanged would be a good choice. Well as it turns out the row isn't added to the table in the OnRowChanged event infact there is no event which you can catch after the row has been added to the table. Now is that a bug or is it by design?
     
    So the workaround that i had to do was to get the row from the DefaultView of the table. The defaultView needs to have the newly added row so that any controls that are bound correctly show newly added rows.

  • VSS Automation script

    In our company we have a policy of creating a checkin mail that describes the files that you are checking in and what changes or bugs have been fixed in that checkin. The process of creating the mail involved opening VSS and then getting a list of all checked out files and then copying and pasting that to the mail. I've always wanted to get into windows scripting and i thought what better oppurtunity than this. So i wrote this small script that gets a list of all checked out files from VSS and then creates a new mail with the required info already filled in.
     
     
      var oVss = new ActiveXObject("SourceSafe");
      oVss.Open("
    <Insert path to srcsafe.ini>");
      var oProj = oVss.VSSItem("<Insert project path e.g. $/");
        
      var allProjects = new Array();
      allProjects = GetAllProjects(oProj,allProjects);
        
      var output = "";
      var projItem;
      var projEnumerator = new Enumerator(allProjects);
      for (; !projEnumerator.atEnd() ; projEnumerator.moveNext() )
      {
          projItem = projEnumerator.item();
          var checkouts = GetCheckedOutFiles(projItem);
       
          if(checkouts.length > 0)
          {
              output += projItem.Spec + "\n";
              var checkoutEnumerator = new Enumerator(checkouts);
              for(;!checkoutEnumerator.atEnd();checkoutEnumerator.moveNext())
              {
                  var checkoutItem = checkoutEnumerator.item();
                  output += "\t" + checkoutItem + "\n";
              }
        
              output += "\n";
          }
      }
      
      var olApp = new ActiveXObject("Outlook.Application");
      var mailItem = olApp.CreateItem(0 /*olMailItem*/);
      mailItem.Recipients.Add("<Insert e-mail address to send mail to>");
      mailItem.Body = "\n" + output;
      mailItem.Display();
      
      function GetCheckedOutFiles( projectItem )
      {
          var checkouts = new Array();
          var itemEnumerator = new Enumerator(projectItem.items(false));
          for(; !itemEnumerator.atEnd(); itemEnumerator.moveNext())
          {
              var item = itemEnumerator.item();
              //File
              if(item.Type == 1/*VSSITEM_FILE*/ && item.IsCheckedOut == 2 /*VSSFILE_CHECKEDOUT_ME*/)
              {
                   checkouts.push(item.Name);
               }
           }
           return checkouts;
      } 
      
      function GetAllProjects( rootItem )
      {
          var projects = new Array();
          var items = new Enumerator(rootItem.items(false));
       
          for(;!items.atEnd();items.moveNext())
          {
              var item = items.item();
              //Project
              if(item.Type == 0 /*VSSITEM_PROJECT*/)
              {
                  projects.push(item);
          
                  var subProjects = GetAllProjects(item);
                  var subProjectEnumerator = new Enumerator(subProjects);
                  for(;!subProjectEnumerator.atEnd();subProjectEnumerator.moveNext())
                  {
                      var subProjectItem = subProjectEnumerator.item();
                      projects.push(subProjectItem);
                  }
              }
       }
        return projects;
      }
      
      function printItems(items, prop)
      {
          var itemEnumerator = new Enumerator(items);
          for(;!itemEnumerator.atEnd();itemEnumerator.moveNext() )
          {
              var item = itemEnumerator.item();
              WScript.Echo(item[prop]);
           }
      }

  • What a way to start the new year..

    On 3rd January i got a mail from Microsoft saying that i had been selected as an MVP for Visual C# , now that is some new years gift. I am waiting for my first set of MSDN Universal DVD's ... woot :)