Kevin Castle Dot Net
MyPicture.gif in content/binary
Navigation
RSS 2.0
Calendar View
<October 2008>
SunMonTueWedThuFriSat
2829301234
567891011
12131415161718
19202122232425
2627282930311
2345678
Categories
On this page....
Categories
Blogroll

Powered by: newtelligence dasBlog 1.9.6264.0

Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2008 , Kevin Castle

Send mail to the author(s) E-mail

 Wednesday, March 21, 2007

About 3 months ago I had a need to do some in-memory sorting on a generic list of objects which were being bound to a GridView control. Due to the fact that we were not working with standard ADO.NET objects and that LINQ has not been fully released, we decided to get clever and come up with a simple sorting method which could handle the case where the a list of objects could be sorted by any one of the fields which was clicked on the GridView control. Note: For the sake of simplicity, I created a dumbed down version of both the object and the sorting method, such that all properties were strings.

For weeks I had heard Sasha talk about how neat anonymous methods were in .NET 2.0, so we sat down and wrote out this nice little SortBy() function. 1st we enumerated through the generic list. 2nd we took the passed propertyname and did a compare between the properties in the two different customer objects. 3rd we used the SortDirection to determine how we would return the compare results. The result, a great little method which is capable of sorting a generic collection with only the objects propertyname and the sortdirection supplied.

 

public class CustomerList : List<Customer>
{

/// <summary>
/// Sorts the CustomerList using Generics, Anonymous Methods, and Reflection 
/// </summary>
/// <param name="propertyName">Property Name to sort the List with</param>
/// <param name="sortDirection">Direction to sort the List</param>
public void SortBy(string propertyName, SortDirection sortDirection)
{
    this.Sort
    (
        //Anonymous method used sort the base generic list.
        delegate(Customer item1, Customer item2)  
        {
            //Use reflection to get the Properties
            PropertyInfo prop1 = item1.GetType().GetProperty(propertyName);
            PropertyInfo prop2 = item2.GetType().GetProperty(propertyName);

            if (prop1 == null || prop2 == null)
            {
                throw new ArgumentException("Invalid property name: " + 
                    propertyName + " specified.");
            }

            //Get the property values from each of the objects
            string value1 = (string)prop1.GetValue(item1, null);
            string value2 = (string)prop2.GetValue(item2, null);

            int compareVal = Comparer.Default.Compare(value1, value2);
            if (sortDirection == SortDirection.Ascending)
                return compareVal;
            else
                return compareVal * -1; //return the negated value
        }
    );

}

}

public class Customer
{
    private string _id;
    private string _firstName;
    private string _lastName;
    private string _age;

    public string ID
    {
        get { return _id; }
        set { _id = value; }
    }

    public string FirstName
    {
        get { return _firstName; }
        set { _firstName = value; }
    }

    public string LastName
    {
        get { return _lastName; }
        set { _lastName = value; }
    }

    public string Age
    {
        get { return _age; }
        set { _age = value; }
    }

}


kick it on DotNetKicks.com

Post Date: Wednesday, March 21, 2007 2:38:41 PM (Pacific Standard Time, UTC-08:00)
Disclaimer | Comments [3] | Trackback   #
 Tuesday, March 20, 2007

Old news...but very cool if you didnt already know....Team Foundation Server Power Tools v1.2 was released.

The Microsoft Visual Studio 2005 Team Foundation Server Power Tool (formerly known as Power Toys) is a set of enhancements, tools and command-line utilities that improve the Team Foundation Server user experience. This release includes two new command-line tools for the developer and three non-command line tools: a process template editor, a set of custom check-in policies, and a test tools build task:

  • Team Foundation Server Power Tool Commands (tfpt.exe) - A command-line tool with enhanced functionality for Team Foundation Version Control with graphical user interfaces for some commands.
  • Process Template Editor - A tool integrated with Visual Studio for authoring custom work item types and some of the associated process template components.
  • Check-In Policy Pack - A set of handy check-in policies to address needs customers have expressed.
  • Test Tools Build Task - A tool that allows running unit tests by simply specifying the DLLs, or by specifying a file name pattern in TfsBuild.proj, instead of using .vsmdi files to specify tests to run.

I was a little bummed that the check-in policy pack didn't have any of the policies which I had requested (laughs)(especially since I posted on sending all of your comments). With that aside I couldnt have been happier with this release of the Process Template Editor. The integration with visual studio, the form control, and the validations were a great upgrade in this release. Note: You must first install the Domain-Specific Language Tools for Visual Studio 2005 in order for the Process Template Editor to appear in the Team Menu.

Here are a few screenshots of some of the process template editor features:

Screen - Editing the Process Template

Screen - Editing a work item type

Screen - Previewing the work item control

Screen - Work Item workflow

In the end, I couldn't be happier because this release came at the perfect time for me. I am steadily working on my Master's Project and alot my project will require me to customize the MSF for Agile process template, work items, and reports. Currently, my tentative title is "Customizing Team Foundation Server Process Templates for Software Quality Improvements". I know its quite a mouthfull, but I figured it would be a great way to learn the ins-and-outs of TFS and how to apply some of my MSE Master's knowledge to Microsoft's latest and greatest.


Post Date: Tuesday, March 20, 2007 8:13:57 PM (Pacific Standard Time, UTC-08:00)
Disclaimer | Comments [0] | Trackback   #