Archive

Archive for August, 2011

TFS2010: Retrieve Associated Workitems to Changesets TFS API


How to Retrieve Workitems Associated to Changesets in TFS using C# and VB.net

You need to add the following references

Microsoft.TeamFoundation.Client.dll

Microsoft.TeamFoundation.VersionControl.Client.dll

Microsoft.TeamFoundation.WorkItemTracking.Client.dll

They are located at “C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\ReferenceAssemblies\v2.0\” on my Windows 7 instance


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.VersionControl.Client;
using Microsoft.TeamFoundation.WorkItemTracking.Client;

namespace ConsoleApplication2
{
    class Program
    {
        static void Main(string[] args)
        {
            var changeset = GetChangeset(new Uri("http://win7-pc:8080/tfs/defaultcollection"), 21);
            foreach (var w in changeset.WorkItems)
            {
                Console.WriteLine("WorkItemId:" + w.Id);
                Console.WriteLine("WorkItemTitle:" + w.Title);

            }
            Console.ReadLine();
        }

        private static Changeset GetChangeset(Uri serverUri, int changesetId)
        {
            var tfs = new TfsTeamProjectCollection(serverUri);
            var svc = tfs.GetService<VersionControlServer>();
            var changeset = svc.GetChangeset(changesetId);

            return changeset;
        }
    }
}

 

Imports Microsoft.TeamFoundation.VersionControl.Client
Imports Microsoft.TeamFoundation.Client
Imports Microsoft.TeamFoundation.WorkItemTracking.Client

Module Module1

    Sub Main()

        Dim changeset As Changeset = GetChangeset(New Uri("http://win7-pc:8080/tfs/defaultcollection"), 21)
        For Each w As WorkItem In changeset.WorkItems
            Console.WriteLine("WorkItemId:" & w.Id)
            Console.WriteLine("WorkItemTitle:" & w.Title)
        Next

        Console.ReadLine()

    End Sub

    Function GetChangeset(ByVal serverUri As Uri, ByVal changesetId As Integer) As Changeset
        Dim tfs As TfsTeamProjectCollection = New TfsTeamProjectCollection(serverUri)
        Dim svc = tfs.GetService(Of VersionControlServer)()
        Dim changeset As Changeset = svc.GetChangeset(changesetId)

        Return changeset
    End Function
End Module

Advertisements
Categories: .NET, C#, TFS, TFS2010, VB Tags: , , ,

WordPress: You are using an insecure browser! Using Internet Explorer 9


In the Dashboard of your WordPress blog you may get the following warning when using the latest version Internet explorer (I was using IE9)

Solution

Turn off compatibility view

Categories: Wordpress Tags: ,

ASP.NET Move Link Elements from the Body Element to Head


ASP.NET: Move Link Elements from the Body Element to Head

Today at a client site, we use a custom asp.net template and some 3rd party custom controls. to build the asp.net pages The custom template is a standard template by the company and we have to use it. Long story short, the template doesn’t initialize the Head property on the page. Hence when 3rd part custom controls finds that page.head ==null, it registers the webresources, as link elements, into the body of the page. Hence, the page fails xhtml strict validation check.

To fix that behaviour I wrote the following code:

Protected Overrides Sub Render(ByVal writer As System.Web.UI.HtmlTextWriter)
Dim sbPageHtml As New StringBuilder
        'Get the html to be rendered
MyBase.Render(New HtmlTextWriter(New StringWriter(sbPageHtml)))
Dim strPagHtml = sbPageHtml.ToString()
'find the occurences of
Dim matches() As String = (From m As Match In Regex.Matches(strPagHtml, "*") _
Select m.Value).ToArray()
        'matches exist
        If matches.Length > 0 Then
'remove occurances from html
Dim toRenderPageHtml As String = Regex.Replace(strPagHtml, "*", "")
           'Write found link tags into the head tag
toRenderPageHtml = toRenderPageHtml.Replace("", String.Format("{0}", String.Join("", matches)))
            writer.Write(toRenderPageHtml)

        Else 'no matches found, no modifications required
writer.Write(strPagHtml)
        End If
    End Sub

If you can think of other solutions, feel free to post them in the comment section.

Categories: .NET, asp.net, VB Tags: , ,