Go to content Go to navigation Go to search

Brokenwire.NET::NET

Microsoft Sync Framework
· 2008-03-05 14:10 by Thijs Kroesbergen for Brokenwire.NET

Yesterday evening I did a presentation about the Microsoft Sync Framework. The text on the slides is mostly in Dutch, but there are some pretty pictures to entertain you as well.

I’ve made a copy of the slides available, and the code for the demos shown is also downloadable. For the Ado sync demo you’ll need a copy of the Northwind database on your SQL 2005 instance, a database backup is included in the zip. The file sync only requires a source and a destination folder. Both projects will build in Visual Studio 2008, after you’ve installed the Sync Framework bits.

Please leave me a comment if you attended presentation (and tell me if you liked it)!

Permalink -

Leaping in PowerShell
· 2008-02-29 14:04 by Thijs Kroesbergen for Brokenwire.NET

Because today is a special day, Leon decided to use C# to calculate a leap year. Because I'm in the PowerShell mood, I'll use that to do exactly the same thing!
Are you ready? Here it is:

[DateTime]::IsLeapYear($year)

Can you see the connection between C# and PowerShell?

Permalink -

Publishing test results to TFS
· 2008-02-28 09:06 by Thijs Kroesbergen for Brokenwire.NET

When running (unit-)tests outside your build process it is still possible to publish the test results back to the build you're testing. For this you can use MsTest.exe or Visual Studio and you need the Team Explorer bits installed. Because we implemented a fully automated system-integration testing system we wanted to use the command line to start the tests and have the results published back to TFS.

So, straight from the MsTest /?:

The following options are also available if Team Explorer is installed: /publish:[server name] Publish results to the Team Foundation Server. /publishbuild:[build name] The build identifier to be used to publish test results. /publishresultsfile:[file name] The name of the test results file to publish. If none is specified, use the file produced by the current test run. /teamproject:[team project name] The name of the team project to which the build belongs. Specify this when publishing test results. /platform:[platform] The platform of the build against which to publish test results. /flavor:[flavor] The flavor of the build against which to publish test results.

That's easy! Yes, but, hmm not so easy after all....

Here is the catch (which took me a lot of time to figure out): You need to specify the value for the platform parameter exactly the same as you have it defined in your build! Our build is configured with "Any CPU" but when passing "x86" seemed to work as well, except that the results would just disappear. This is what happened: when passing the wrong platform MsTest will publish your results to TFS, but you can not find them ever again! When you pass the correct parameters the results will be attached to the build tested (and they are visible in the build store) and results file (.trx) will be placed in the drop location for that build.

The 4 possibilities for platform are:

A full example of using the MsTest.exe command to kick the test and publish the results to TFS:

MSTest /nologo /testcontainer:"MyTests.dll" /runconfig:"localtestrun.testrunconfig" /resultsfile:"MyTestResults.trx" /test:MyUnitTest /publish:"http://TfsServer:8080" /publishbuild:"DailyTestBuild_20080227.1" /teamproject:"TestProject" /platform:"Any CPU" /flavor:Debug

Now if MsTest (or the TFS webservice) would just have returned an error if you passed in the wrong platform, that would have been much better (and saved me a lot of time)...

Permalink -

Using the Team Foundation Object Model with PowerShell
· 2008-02-26 12:45 by Thijs Kroesbergen for Brokenwire.NET

After my first steps in PowerShell I wanted to do something more. I wanted to manipulate the TFS build store from within PowerShell (because I installed TFSDeployer which responds to "Build Quality Changed events" from TFS). So after some Google-ing I found the "get-tfs.ps1" script written by James Manning. His script wraps the Team Foundation Server SDK (which is .NET object model to access TFS) into one nice PowerShell script.

The only thing his script could not do, was manipulate the build store. But with the addition of one line I made this possible. His version also was a "script-as-function" while I'd rather have just a separate function that I could put in my script library. The script now look like this:

function get-tfs ( [string] $serverName = $(Throw 'serverName is required') ) { # load the required dll [void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.TeamFoundation.Client") $propertiesToAdd = ( ('VCS', 'Microsoft.TeamFoundation.VersionControl.Client', 'Microsoft.TeamFoundation.VersionControl.Client.VersionControlServer'), ('WIT', 'Microsoft.TeamFoundation.WorkItemTracking.Client', 'Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItemStore'), ('BS', 'Microsoft.TeamFoundation.Build.Common', 'Microsoft.TeamFoundation.Build.Proxy.BuildStore'), ('CSS', 'Microsoft.TeamFoundation', 'Microsoft.TeamFoundation.Server.ICommonStructureService'), ('GSS', 'Microsoft.TeamFoundation', 'Microsoft.TeamFoundation.Server.IGroupSecurityService') ) # fetch the TFS instance, but add some useful properties to make life easier # Make sure to "promote" it to a psobject now to make later modification easier [psobject] $tfs = [Microsoft.TeamFoundation.Client.TeamFoundationServerFactory]::GetServer($serverName) foreach ($entry in $propertiesToAdd) { $scriptBlock = ' [System.Reflection.Assembly]::LoadWithPartialName("{0}") > $null $this.GetService([{1}]) ' -f $entry[1],$entry[2] $tfs | add-member scriptproperty $entry[0] $ExecutionContext.InvokeCommand.NewScriptBlock($scriptBlock) } return $tfs }

The way this works is that the "propertiesToAdd" array is looped through, and the $tfs powershell object is extended with a new object with the names of the first array element. The actual objects are retrieved from the third array element and they are retrieved from the assemblies in the second array element.
This function is used to create a $tfs object, like this:

$tfs = get-tfs http://YourTfsServer:8080

Next, you can use one of the properties of the $tfs object to do cool stuff.

VCS gives you access to the version control server. For example, you can download a single file, without an active workspace mapping:

$tfs.VCS.DownloadFile("$/Test Project/ClassLibrary1/ClassLibrary1.sln", "C:\ClassLibrary1.sln")

Or you can map a temporary workspace to retrieve all files in a specific folder:

$workspace = $tfs.VCS.CreateWorkspace([System.Guid]::NewGuid().ToString(), $tfs.AuthenticatedUserName) $workspace.Map("$/Test Project/Dev/Branch/SomeFolder", "C:\SomeFolder") $workspace.Get() $workspace.Delete()

WIT lets you use the work item store. For example, you can retrieve the uri, title and state of a workitem:

$tfs.WIT.GetWorkItem(1) | Format-List uri, title, state

BS is the wrapper for the build store. Let's do something more complex: retrieve the last successfully completed build and once this build is found, update the Build Quality.

$build = $tfs.BS.GetListOfBuilds("Test Project", "TestBuild") | where {$_.Buildstatus -eq "Successfully Completed"} | sort -property FinishTime -desc | select -first 1 $tfs.BS.UpdateBuildQuality($build.BuildUri, "Ready for Initial Test")

CSS contains the ICommonStructureService interface. This interface gives you access to the more common properties of you TFS server. For example, retrieve all projects on your server (which is just a bit boring...):

$tfs.CSS.ListAllProjects()

The last one, GSS, gives access to the group security service interface. The next two lines of script will give you a list of all the groups (both windows and application groups) a specific account is a member of:

$groups = $tfs.gss.ReadIdentity('accountName', 'YourNTAccountName', 'direct').memberof $groups | foreach-object -process { $tfs.GSS.ReadIdentity('sid', $_, 'none') } | fl type, displayname

I know I like working with TFS & PowerShell a lot, and I hope you do too. Enjoy!

Permalink -

silverlight rss feed displayer
· 2007-05-22 22:30 by Thijs Kroesbergen for Brokenwire.NET

Tonight I built a small silverlight application which reads this site’s rss feed and displays it in a “nice” format.

See SilveRSS in action!

Getting the animation done was quite simple too, but I did some fine-tuning inside the XAML code myself. Probably because I don’t know Expression Blend well enough yet.

The biggest challenge was to have the Silverlight applet decypher the rss-xml layout. But actually all that is very basic .NET programming.
The code to retrieve the rss data and parse the XML looks like this:

    Uri uri = new System.Uri("http://www.brokenwire.net/bw/rss");
    BrowserHttpWebRequest request = new BrowserHttpWebRequest(uri);
    HttpWebResponse response = request.GetResponse();
    StreamReader responseReader = new StreamReader(response.GetResponseStream());
    string rawvalue = responseReader.ReadToEnd();
    XmlReader xr = XmlReader.Create(new StringReader(rawvalue));
    while (xr.ReadToFollowing("item"))
    {
         //RssItem is a struct to contain the data for one item
         RssItem item;
         xr.ReadToFollowing("title");
         item.title = xr.ReadElementContentAsString();
         xr.ReadToFollowing("description");
         item.description = Strip(xr.ReadElementContentAsString());
         xr.ReadToFollowing("link");
         item.link = xr.ReadElementContentAsString();
         // Add items to a list
         _rssItems.Add(item);
    }

Controlling the animations is just a matter of catching the Storyboard “Completed” events.

Other examples I found on the web are using the power of the webserver to create XAML code on the server, and displaying that on the client. But I didn’t want to and didn’t need to write any server-side code in this example.

Permalink -

Popfly
· 2007-05-21 12:36 by Thijs Kroesbergen for Brokenwire.NET

While playing with Silverlight I also bumped upon this nice new Microsoft project: Popfly
(The url also has the new Microsoft TLD .MS

Microsoft Popfly

Popfly enables non-developers to quickly build sites and mashups. It allows users to re-use each others work.

The whole Popfly project was built on Silverlight and AJAX technology, and built in just 6 months!

It also looks like it’s possible to work on Popfly projects using Visual Studio as well, cool!

There is a demo video here

I applied for my own popfly account, but you’ll have to get invited by Microsoft at the moment.. so I can’t login, yet.
(In the meantime we I’ll just have to suffer looking at the low-res wallpapers)

Permalink -

Previous Next