Wednesday, September 12, 2007

DataTable Select Method

The Select method is really handy for filtering and sorting the rows you need from a strongly typed dataTable. It has 3 overloads Select() for returning all the rows as an array select(stringFilter) for returning the rows with out sorting and Select(stringFilter,stringSort) for returning rows with sorting. Here is quick way to fire everyone with the first name of bob in your employee management application.
EmployeeDataSet.PeopleRow[] people = peopleDataTable.Select("FirstName = bob AND Fired = 0", "LastName") as EmployeeDataSet.PeopleRow[];

 foreach (EmployeeDataSet.PeopleRow person in people)
 {
     person.Fired = true;
 }

more Info:
MSDN
even better example

#     Comments [3]  
kick it on DotNetKicks.com
 Thursday, August 23, 2007

Code Search Engine

Found a cool code search engine called Koders.com that crawls open source projects by language for code examples. It has a great syntax highlighting and plugs into your IDE.
 
#     Comments [0]  
kick it on DotNetKicks.com
 Wednesday, August 22, 2007

Eponymous Laws Of Software Development

Do you want to sound smart, impress your friends, increase your chances of scoring next time you go out on a night on the town? Take a look at Phil Haack's blog post on 19 Eponymous Laws Of Software Development.

My Favorites are Sturgeon's Revelation Ninety percent of everything is crud (it seems to me to have a duel meaning crud = Create Update and delete or crud = crap) and Hofstadter's Law A task always takes longer than you expect, even when you take into account Hofstadter’s Law.

#     Comments [2]  
kick it on DotNetKicks.com
 Tuesday, August 21, 2007

Measuring Time Elapsed in Code

Some times you need to time an algorithm or method when trying to increase performance of an application. There is a quick and easy way to do this using the StopWatch class in System.Diagnostics.

System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
sw.Start();
TestMethod();
sw.Stop();
Debug.WriteLine(sw.ElapsedMilliseconds.ToString());


#     Comments [1]  
kick it on DotNetKicks.com
 Wednesday, June 13, 2007

Mission Complete: Continuous Integration .Net

I have completed or at least gotten a good start with Continuous Integration. What I have done may not be doctrine but it is what I could find to be the simplest and cleanest way. There are in my opinion 4 main parts you must have in order to achieve CI. First you must have a good repository, second you need to have a development tree setup for your project, then each project needs a build script, and finally you need to setup an automated build server. For more on continuous integration check out Martin Fowlers article and Jay Flowers article.

  1. Repository

The repository/version control/source code management, what ever you like to call it is the first thing that needs to be established. There needs to be a common place where your entire source is kept so that your build server can know where to get the latest version (head). I choose Subversion (svn) with TortoiseSVN. I was using visual source safe and I was happy about this, but like my grandpa is happy with dial-up, I had no idea what I was missing. If you are using source safe switch now to Subversion its open source and its free you will not regret it.

If you would like to know just about everything a user would need to know about modern repositories go to Eric Sink’s online book: Source Control HOWTO.

  1. Creating Development Tree

Basically the Development tree is the folder structure/organization of your project. A good development tree is defined by Mike Roberts as easily inheritable on new environments, requires little maintenance, easily maintained, supports productivity, and is consistent. I tried to follow his guide lines in his article: How to Setup a .NET Development Tree. I am using a refactored patterns project I did earlier for this example. I define the trunk/root folder name to be the same as my visual studio solution. In this folder I have 3 other folders src, lib, and tools.

The src contains all the developer created content need to build the solution. The lib contains all references dlls that are needed for the project and are not built with the solution. The tools folder will house things like NAnt, NUnit, FXCop, and whatever else you need to help build quality software. You can also include a docs folder to contain the documentation. Another good source on development trees is an article on

  1. Build Script
To automate my builds I choose NAnt  + NAntContrib. I save the build script in the root of the project with the file name of [projectName].Build and a go.bat that contains one line that calls NAnt with the build script.

@tools\nant\Nant.exe -buildfile:[projectName].build %* > buildOut.txt

 The > BuildOut.txt saves the out put of the build result to a text file I found this convenient to view how the build went. My build script should be made in a way that is easily implemented, easy to maintain, and need as little maintenance as possible. I include this as an existing solution item that way it can be edited along with the src.

<?xml version="1.0" encoding="utf-8"?>
<project name ="nant" default ="all">

  <!-- The Build Directory -->   
  <property name="build.dir" value ="build"/>

  <!-- Define Default targets and the order they run -->
  <target name="all" depends="clean, compile, run-unit-tests" description="Compile and Run Tests"/>

  <!-- delete build folder, everything in this folder should be created on the build,
    so it should be safe to delete at any time. -->
  <target name="clean" description="Delete automated build artifacts">
    <delete dir="${build.dir}" if="${directory::exists(property::get-value('build.dir'))}"/>
  </target>

  <!-- Compile solution with msbuild task(Only Available with NAntCOntrib)
    if it is 2003 use solution task all build properties should be
    set up in a new VS Automated Build configuration. -->
  <target name="compile">
  <!-- point msbuild to the solution file with should be at the root of your src folder-->   
    <msbuild project="src\Patterns.sln">
      <property name="Configuration" value="Automated"/>
    </msbuild>
  </target>

  <!-- RunUnit tests -->
  <target name ="run-unit-tests">
    <!-- Creates Nunit Reprot Directory-->
    <mkdir dir="${build.dir}\test-reports"/>
    <exec program="nunit-console.exe" basedir="tools\nunit"
          workingdir="${build.dir}">
      <!-- The dll that contains your test that
    should now be in the build folder -->
      <arg value="Strategy.Test.dll"/>
      <!-- Location and name of the NUnit test report -->
      <arg value="/xml:test-reports\UnitTests.xml"/>
    </exec>
  </target>

</project>

In side VS I set up a new visual studio build configuration called Automated. Automated is basically a copy of the default configuration Release but I changed the folder it builds to be ..\..\build\.

  1. Build Server
The final step is implementing your build server. I have heard of people just using scheduled tasks for this but that doesn’t sound very useful. I wanted the build done when some one commits a change to the repository. For this I used CruiseControl.NET. CruiseControl.NET is an Automated Continuous Integration server, implemented using the Microsoft .NET Framework. It works with majority of the source code management (SCM) tools out there and more importantly it works with subversion. The installation was simple just download and run the MSI but the configuration can be a little difficult because of the flexibility available. To get it running you need to edit the ccnet.config.

<cruisecontrol>
    <!-- Each Project needs the following setup -->
<project name="Patterns">
<!-- The Working folder/checked out
folder for the project on the server -->
<workingDirectory>H:\MyApps\Patterns</workingDirectory>
<!-- sourcecontrol setup -->
<sourcecontrol type="svn">
  <!-- URL to the project in the repository -->
    <trunkUrl>http://www.myrepos.com/myapps/Patterns/</trunkUrl>
    <executable>D:\Program Files\Subversion\bin\svn.exe</executable>
    <!-- The Working folder/checked out
    folder for the project on the server -->
    <workingDirectory>H:\MyApps\Patterns</workingDirectory>
</sourcecontrol>
<!--Build task-->
<tasks>
    <nant>
     <!-- Nant EXE for project -->
        <executable>H:\MyApps\Patterns\tools\Nant\nant.exe</executable>
    <!-- where the build file lives -->
        <baseDirectory>H:\MyApps\Patterns</baseDirectory>
        <buildArgs></buildArgs>
        <nologo>false</nologo>
        <buildFile>Patterns.build</buildFile>
        <buildTimeoutSeconds>1200</buildTimeoutSeconds>
    </nant>
</tasks>
<!-- reporting information -->
<publishers>            
    <merge>
        <files>        
            <!-- Location of Unit test reports -->
            <file>H:\MyApps\Patterns\Build\test-reports\UnitTests*.xml</file>
        </files>
    </merge>
  <!-- create the log files used by the CruiseControl.NET Web Dashboard -->
    <xmllogger logDir="D:\Program Files\CruiseControl.NET\server\Patterns\BuildLogs" />
  <!--default statistics for capturing during the build process.-->
  <statistics />
</publishers>
</project>
</cruisecontrol>

After that just edit the project, commit the changes, and watch the dashboard build report.


#     Comments [5]  
kick it on DotNetKicks.com
 Friday, June 08, 2007

Getting Started with .Net Development

  

 I am really impressed with the amount of developer support being put out by Microsoft; everything you need to get started is pretty much free. You can download the Express version of Visual Studios and it gives you a majority of its big brothers features which is 300$ IDE, the most notable difference is that the express version is not pluggable. There are different flavors of Visual Studio express, one for windows, web with AJAX, hardware/robotics and game /XNA development.  Although the free IDE is nice and I use visual studio as my primary development tool I am totaly blown away with the amount of resources available for learning. I am not talking about the MSDN Library, most of the time the MSDN documentation just confuses me, but webcast live and On Demand, podcasts and virtual labs are fantastic. There is tons of time worthy information put up here for beginning and advance programmers. It’s the first place I go to when I am trying to learn a new technology. I hear a lot of trash talked about Microsoft everywhere I go but I feel they have the best development support out there.

#     Comments [4]  
kick it on DotNetKicks.com
 Friday, May 25, 2007

Mission: Continuous Integration

When I first accepted this mission I was so excited I imagined my self doing a happy dance, it was a Latin dance because maracas are cool. I thought this was going to be great! I am going to have an automated build process that hooks into source control so it will build the latest check in, run unit test, and then give you feed back on how every thing worked out. I was not in the least bit intimidated by the complexity of how all that may be because well all shops should have this, it can’t be any harder than installing Visual Studio, right? After about an hour of research my head exploded.

I have a lot of learning to do but I have found some references that will hopefully lead me in the right direction.

Reference:

#     Comments [0]  
kick it on DotNetKicks.com
 Tuesday, May 08, 2007

How do I learn?

    I was at school the other day talking to a class mate he was admitting to me that some thing big needs to change in his life. He was about to graduate with a BS in Software Engineering and he all ready has his AAS in Software Application Programming, but he still did not have confidence in his abilities as a programmer. This made me think; we started school at the same time with about the same skill level. Why has my skill and confidence in them surpassed his? I believe it has to be because I strive to find and consume knowledge in multiple ways.
    I regularly listen to podcasts and watch webcast. I am also subscribing to multiple blogs from people I believe to be successful and knowledgeable programmers. I always have at least one book that I am reading that is related to the field. I attend classes on programming as well as try to instruct others on techniques through my blog as well as in person. On top of my work, I always have a side project going on that allows me to practice new and interesting technologies. That seems like a lot and it is, but I enjoy it. I guess that is the real answer, you have to enjoy it to be proficient at it.

#     Comments [0]  
kick it on DotNetKicks.com