Tuesday, October 14, 2008

Excluding config file from version control

Every application has some kind of configuration file to load settings. For instance, ASP.NET applications make use of web.config file to get the connection string for database operations. Similarly, desktop applications use INI file. While developing the application, each developer use configuration file as per their need. If the source is maintained in source control system, developers have to take extra care not to commit such configuration files. If somebody does it by mistake, everybody's file will be altered while updating from the source control. There is a simple way to avoid such situation. Don't put the configuration file under source control. Instead, put a template of the file, something like "app.config.tmpl". Then, after the initial checkout, have the users do a normal OS copy of the template to the proper filename, like "app.config" and have users customize the copy. The file is unversioned, so it will never be committed.

Thursday, August 21, 2008

Retrieve full name from Active Directory using C#

Once upon a time, I was given a task to build a simple attendance system to replace the attendance register in our office. Starting from sourceforge.net, I tried to find open source application to fit our requirement. After spending few hours in the Internet, I could not convinced myself with the applications that I came across. Then I suddenly realized that we are using Active Directory to log in to domain and also thought that if I could get the user detail from AD somehow, I can build a system which does not require any user login. Finally, I was able to find the code to get the full name of the current Windows user and build a small prototype for attendance system. The logic behind this application is to get the user detail from Active Directory and simply log attendance detail to another database. This will reduce the overhead of loggin in to the system as well as user administration part. Below is the code to get the full name of Windows user;
using System.DirectoryServices;

public static string GetFullName(string strLogin)
    {
        string str = "";
        string strDomain;
        string strName;

        // Parse the string to check if domain name is present.
        int idx = strLogin.IndexOf('\\');
        if (idx == -1)
        {
            idx = strLogin.IndexOf('@');
        }

        if (idx != -1)
        {
            strDomain = strLogin.Substring(0, idx);
            strName = strLogin.Substring(idx + 1);
        }
        else
        {
            strDomain = Environment.MachineName;
            strName = strLogin;
        }

        DirectoryEntry obDirEntry = null;
        try
        {
            obDirEntry = new DirectoryEntry("WinNT://" + strDomain + "/" + strName);
            System.DirectoryServices.PropertyCollection coll = obDirEntry.Properties;
            object obVal = coll["FullName"].Value;
            str = obVal.ToString();
        }
        catch (Exception ex)
        {
            str = ex.Message;
        }
        return str;
    }

Wednesday, April 30, 2008

Some useful tools for Delphi developers

I was always fascinated by the tools that are available to .NET developers which help to increase the productivity, like unit testing framework (NUnit), documenation tool and automated build tool (NANT). So, I started looking for same for Delphi. Starting with the documentation tool, I tried few applications but not so promising. Lastly I found DelphiCodeToDoc and it worked well for me. Though there are few bugs, but the tool is great and it supports JavaDoc style documentation. Again, I found that the author of this application is offering a template for GExperts. Tried that and worked well. Next target was unit testing framework. The only one framework I found was DUnit. Also tried this tool and worked very well for me. Finally, I started searching for automated build tool for Delphi application. The one I tried was WANT. Due to the poor documentation, I was forced to learn the whole building process from ANT website and looking into WANT's own build script. In a few hours, I was able to write a script to build my first test application including unit test with DUnit. Super cool. Somebody said "Sky is the limit". Very true. Since my last unit test used GUIRunner, I wanted to try something with console. Could not find a clue how to do that. Well, after going through the build script of WANT again and again, I noticed that we need to create a DLL version of test application. Tried it and worked well. I will try explain this process in detail in my next post.

Tuesday, April 15, 2008

Celebrating new year

Believe it or not, we are in the year 2065 here in Nepal. If you do not know, we have our own calendar. I've been planning a vacation for new year for a long time. I wanted to go outside valley in last December but my son was sick that time. So, I did not want to miss our new year this time and made a plan. Our new year was on the 13th of April and we went to Godavari Village Resort to relax. Since we were going with the kid, I did not wanted to go far from the city. The resort is just 7 KM away and very peaceful. I can't explain how much I enjoyed with my family there. My wife and I decided to make a plan for such short trip for every new year (either in English or in Nepali year). Let's see how it goes.

Thursday, April 10, 2008

Constitutional Assembly Election in Nepal

Today is the biggest day in the history of Nepal. Today, we are having an election for Constitutional Assembly for the first time. This election will select the group of people who will be responsible to write the new constitution of Nepal. Everybody is hoping for stable political situation and long lasting peace in the country after this election. Till now, everything is going well, except for few minor incidents in the remote part of the country. Also, I cast a vote today for the first time in my life. :-)

Tuesday, April 08, 2008

New Delphi Magazine

This is good news to all Delphi developers that there is a new magazine about Delphi, "Blaise Pascal". The printed version costs around 40 euro per year. But you can get the download version for FREE. However, you need to pay for the code or program if you decide to go for free version. I am taking this as a good news because I still remember closing down of Delphi magazine last year. I started thinking that nobody uses Delphi anymore but with this magazine (and other development), I already started seeing the light at the end of the tunnel.

Wednesday, April 02, 2008

Back again

I don't believe that it's been almost 7 months since my last post here. Anyway, lot of things happened in 7 months of time. During this time, I was given more responsibilities in the office. I am now part of a team which is responsible for auditing CMMI implementation. Also, I joined EMBA and my classes started from Feb 17th. We created a group in Google to share information regarding course materials and other stuffs. I am the manager of that group. After joining EMBA, I am feeling young again :-). I remember my collage day and enjoying a lot with new friends there. Most importantly, I now don't have time to watch TV or movies. I have to attend the classes on Saturdays. Although we also have classes on Sundays, it's only in the evening. Thank God. I did not have enough time to spend on photography, so I decided to sell my camera. I will probably save some money and go for dSLR in the near future. ;-) Bought a laptop recently. Now I don't have money for new camera. Damn! These days I am totally into management business. Haven't had chance to look into technical things and feeling myself way to far from the latest development in technology. The only thing I should be focusing now is 'Time Managment'. I sometime feel guilty for not giving enough time to my family. I hope Google will help me finding something from which I can learn to manage my time efficiently.