Monday, December 31, 2012

NUnit Test Adapter for Visual Studio 2012 updated

Starting from Visual Studio 2012 the testing infrastructure became extensible making it possible to add support for other test frameworks without the need of 3th party plugins like Resharper or Gallio.

Just before the year ended, the NUnit team released a new version(beta 4) of their NUnit Test Adapter for Visual Studio, with support for VS 2012 Update 1. The new release, version 0.94, works with the VS 2012 RTM as well but shows off some extra features when used with the update.

The biggest addition to the Adapter in this release is that it now supports Traits. NUnit Properties and Categories are translated in to Visual Studio traits and you can sort the display of tests by trait or filter on them. This goes a long way toward making the Visual Studio Test Explorer useful in running large sets of tests.

Release notes for this version can be found here: http://nunit.org/index.php?p=vsTestAdapterReleaseNotes&r=2.6.2

More information about Traits here: http://blogs.msdn.com/b/visualstudioalm/archive/2012/11/09/how-to-manage-unit-tests-in-visual-studio-2012-update-1-part-1-using-traits-in-the-unit-test-explorer.aspx

Friday, December 21, 2012

Team Foundation Server 2012 Monitoring Management Pack

Last week Microsoft released the Visual Studio 2012 Team Foundation Server Monitoring Management Pack for monitoring TFS with System Center Operations Manager 2007 SP1 or 2012. You can download it here.

The Team Foundation Server 2012 Monitoring Management Pack provides both proactive and reactive monitoring of Microsoft Team Foundation Server 2012. It monitors TFS components such as application tier server instances, team project collections, build servers, and proxy servers.

Feature Summary
The monitoring provided by this management pack includes availability and configuration monitoring, performance data collection, and default thresholds. You can integrate the monitoring of Team Foundation Server components into your service-oriented monitoring scenarios.

  • Auto discovery of TFS components
  • Implements containment hierarchy, reflecting logical architecture of the Product
  • Implements a proper health model using Monitors
  • Contains tasks, diagnostic and recovery for certain failures
  • Provides events that indicate service outages
  • Provides alerts that show configuration issues and connected data source changes
  • Verification that all dependent services are running

HealthExplorer

Thursday, December 20, 2012

Native JSON parsing

Starting from Internet Explorer 8+, Firefox 3.1+, Safari 4+, Chrome 3+, and Opera 10.5+ browsers support native JSON parsing. But what if your users are still using IE7 (or even worse IE6)?

Here are some of the options I prefer to use:

  • To convert a JSON response to a JavaScript object:
    • If you are using jQuery, use parseJSON. Internally it checks if browser supports JSON.parse, so the fallback is built in.
    • Use the JSON.parse method from the json2.js library from Douglas Crockford. It adds a JSON object to the browser if it doesn’t exists yet.
  • To convert a JavaScript object to serialized JSON string:
    • For jQuery I couldn’t find an out-of-the-box solution, but the following jQuery plugin could do the trick: jQuery.toJSON
    • Use the JSON.stringify method from the json2.js library.

What I also like about the json2.js library from Douglas Crockford is that it allows you to manipulate the serialization process by adding a toJSON method to your JavaScript objects.

When an object value is found, if the object contains a toJSON method, its toJSON method will be called and the result will be stringified. A toJSON method does not serialize: it returns the value represented by the name/value pair that should be serialized, or undefined if nothing should be serialized. The toJSON method will be passed the key associated with the value, and this will be bound to the value

For example, this would serialize Dates as ISO strings:

Date.prototype.toJSON = function (key) {
function f(n) {
// Format integers to have at least two digits.
return n < 10 ? '0' + n : n;
}

return this.getUTCFullYear() + '-' +
f(this.getUTCMonth() + 1) + '-' +
f(this.getUTCDate()) + 'T' +
f(this.getUTCHours()) + ':' +
f(this.getUTCMinutes()) + ':' +
f(this.getUTCSeconds()) + 'Z';
};

Wednesday, December 19, 2012

Updating a Linq to SQL dbml file

As you probably know Microsoft started its journey in ORM land with 2 frameworks: Linq to SQL, a lightweight ORM with some nice features and good performance but tightly coupled to SQL Server and Entity Framework which started as an ugly beast but is now transformed into a good, performant Enterprise ready ORM solution.

So Microsoft decided to stop investing in Linq to SQL and put al its effort in Entity Framework. This means that although Linq to SQL is a nice ORM framework, it’s missing some useful features.

Last week I got a question from a colleague about Linq to SQL. He couldn’t find a way to update the Linq to SQL DBML file so it reflects the changes he made to the underlying database model.

This is just one of the missing features. Luckily there are some workarounds to fix this:

  • Option 1: Remove the changed tables from the DBML designer and drag them again from the SQL explorer window.
  • Option 2: Use the SqlMetalPlus addin. The add-in adds some extra context menu options to all the DBML files in the solution.
    • Create Mapping XML: This command just creates the initial mapping file for you to customize. It just creates a copy of DBML file and changes the file name.
    • Apply Customization: This command applies the custom changes to the existing DBML file.
    • Create/Refresh: This command either creates the initial DBML (or) refreshes the complete DBML with the latest changes from the selected database and then applies the custom changes.

Tuesday, December 18, 2012

Bundling conventions in ASP.NET Bundling and Minification

I talked about the Bundling and Minification NuGet package before. Last week when configuring a new ASP.NET MVC 4 web application, I discovered another nice feature inside this library. Before I had to update the script references each time I upgraded to a new version of jQuery. So somewhere in my code I had a script reference like this:
<script type="text/javascript" language="javascript" src="~/scripts/jquery-1.7.1.js"/>

With the Bundling and Minification library you can create a version independent bundle and set the reference once. So you no longer have to upgrade your script references.

You can see this already in action if you created a new ASP.NET MVC application in Visual Studio 2012.  If you open up  the App_Start\BundleConfig.cs file and examine the RegisterBundles method, you’ll find the following code:

public static void RegisterBundles(BundleCollection bundles)
{
     bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
  "~/Scripts/jquery-{version}.js"));
}
The preceding code creates a new JavaScript bundle named ~/bundles/jquery that includes all the appropriate (that is debug or minified but not .vsdoc) files in the Scripts folder that match the wild card string "~/Scripts/jquery-{version}.js". With a debug configuration, the file jquery-1.7.1.js will be added to the bundle. In a release configuration, jquery-1.7.1.min.js will be added.

The bundling framework follows several common conventions such as:
  • Selecting “.min” file for release when “FileX.min.js” and “FileX.js” exist. 
  • Selecting the non “.min” version for debug.
  • Ignoring “-vsdoc” files (such as jquery-1.7.1-vsdoc.js), which are used only by IntelliSense.
The {version} wild card matching shown above is used to automatically create a jQuery bundle with the appropriate version of jQuery in your Scripts folder. In this example, using a wild card provides the following benefits:
  • Allows you to use NuGet to update to a newer jQuery version without changing the preceding bundling code or jQuery references in your view pages. 
  • Automatically selects the full version for debug configurations and the ".min" version for release builds.

Nice!

Monday, December 17, 2012

Team Foundation Server Sidekicks 2012

Last week Attrice released their Team Foundation Server 2012 version of the Team Foundation Sidekicks.

It offers the same functionality as previous versions but adds support of TFS both on premise and in-the-cloud (Team Foundation Service).

Download version 4.5 of Team Foundation Sidekicks (only for Visual Studio© 2012, Team Foundation Server 2012 and Team Foundation Service).

Friday, December 14, 2012

SignalR Performance Counters

One of the hidden gems in the SignalR framework is a utility called signalr.exe (in the Microsoft.AspNet.SignalR.Hosting.Utils package) that you can use to do a few things.

  • Install/Uninstall SignalR performance counters
  • Generate a static js file for the magic ~/signalr/hubs url.

After installing the Microsoft.AspNet.SignalR.Hosting.Utils NuGet package, you’ll find a SignalR executable in the package folder(under \packages\Microsoft.AspNet.SignalR.Hosting.Utils.1.0.0-alpha2\tools)

  • Open a command prompt(run as Administrator).
  • Browse to the tools folder containing the SignalR.exe file.
  • Run signalr ipc to install the Performance Counters. These performance counters give you more detailed information about your SignalR applications.

clip_image002

    • Remark: To use these on full IIS you need to add the app pool user for your application to the Performance Monitor Users group.
  • Run signalr ghp /path:<path to binaries> to generate a static JavaScript file containing the hub code. This file(server.js) is generated inside the same tools folder.

image

  • If we open up the file we see the magic that SignalR creates for us when calling the ~/signalr/hubs url:
/*!
* ASP.NET SignalR JavaScript Library v1.0.0
* http://signalr.net/
*
* Copyright Microsoft Open Technologies, Inc. All rights reserved.
* Licensed under the Apache 2.0
* https://github.com/SignalR/SignalR/blob/master/LICENSE.md
*
*/

/// <reference path="..\..\SignalR.Client.JS\Scripts\jquery-1.6.2.js" />
/// <reference path="jquery.signalR.js" />
(function ($, window) {
/// <param name="$" type="jQuery" />
"use strict";

if (typeof ($.signalR) !== "function") {
throw new Error("SignalR: SignalR is not loaded. Please ensure jquery.signalR-x.js is referenced before ~/signalr/hubs.");
}

var signalR = $.signalR;

function makeProxyCallback(hub, callback) {
return function () {
// Call the client hub method
callback.apply(hub, $.makeArray(arguments));
};
}

function registerHubProxies(instance, shouldSubscribe) {
var key, hub, memberKey, memberValue, subscriptionMethod;

for (key in instance) {
if (instance.hasOwnProperty(key)) {
hub = instance[key];

if (!(hub.hubName)) {
// Not a client hub
continue;
}

if (shouldSubscribe) {
// We want to subscribe to the hub events
subscriptionMethod = hub.on;
}
else {
// We want to unsubscribe from the hub events
subscriptionMethod = hub.off;
}

// Loop through all members on the hub and find client hub functions to subscribe/unsubscribe
for (memberKey in hub.client) {
if (hub.client.hasOwnProperty(memberKey)) {
memberValue = hub.client[memberKey];

if (!$.isFunction(memberValue)) {
// Not a client hub function
continue;
}

subscriptionMethod.call(hub, memberKey, makeProxyCallback(hub, memberValue));
}
}
}
}
}

signalR.hub = $.hubConnection("/signalr", { useDefaultPath: false })
.starting(function () {
// Register the hub proxies as subscribed
// (instance, shouldSubscribe)
registerHubProxies(signalR, true);

this._registerSubscribedHubs();
}).disconnected(function () {
// Unsubscribe all hub proxies when we "disconnect". This is to ensure that we do not re-add functional call backs.
// (instance, shouldSubscribe)
registerHubProxies(signalR, false);
});

signalR.testHub = signalR.hub.createHubProxy('testHub');
signalR.testHub.client = { };
signalR.testHub.server = {
test: function () {
/// <summary>Calls the Test method on the server-side TestHub hub.&#10;Returns a jQuery.Deferred() promise.</summary>
return signalR.testHub.invoke.apply(signalR.testHub, $.merge(["Test"], $.makeArray(arguments)));
}
};

}(window.jQuery, window));

Thursday, December 13, 2012

Generating QR codes quick and easy in Windows 8

You all probably seen QR codes before, these strange looking images containing any kind of data. Most of the times there are used to embed an URL but you can put any kind of data in it

For a Windows 8 application I’m building I wanted to embed the option to generate QR codes and share these codes using the Windows 8 Share Contracts. The easiest way I found to generate QR codes is by using the Google Chart API. The only thing you need to do is specify the size in pixels of your barcode and the url you wish to encode.

If you invoke a GET request to the Google Chart API using the following query string, you’ll get a generated QR image back:

http://chart.apis.google.com/chart?cht=qr&chs=300x300&chl=http://bartwullems.blogspot.com

Nice and simple!

Wednesday, December 12, 2012

TFS API Blog Series

Since 2009 Shai Raiten is writing about TFS API making his blog one of the best resources for any information about customizing and extending Team Foundation Server.

This resulted in a long list of blog posts:

Basic

Source Control

Testing

Work Items – Definitions and Queries

Areas and Iterations

Builds

Keep going Shai!

Tuesday, December 11, 2012

TFS Publishing to Windows Azure Websites: What to do if you have multiple projects/solutions?

Last week I enabled TFS publishing for a Windows Azure Website.  However the deployment failed because I had multiple projects inside the solution and the build tried to deploy the wrong project.

To fix this I used the following workaround:

  • Create a separate solution for the project you want to deploy and check this solution into source control.
  • Open Team Explorer and connect to your TFS project

image

  • Right click on the Build definition that was created for you when enabled TFS publishing and choose Edit Build Definition...

image

  •    Go to the Process tab and change the Solution To Build to the solution you just created.

image

  • Next time you check in the new solution is used to build and deploy the project.

image

Monday, December 10, 2012

Windows Phone 8 Jump Start training

Last week the Windows Phone team hosted the Windows Phone 8 Jump Start training, a fast-paced and demo-packed learning ‘experience’ tailored to show developers how to build responsive, appealing, and effective applications quickly. All 20 modules are now available online for your on-demand viewing, (or download) on Channel 9.

If you are new to Windows Phone 8, this is a great way to start developing apps right away.

windows-phone-8-start

Friday, December 7, 2012

Toad for Cloud Databases

Looking for a free(!) tool to connect to your Cloud databases? One of the tools I’ve been trying is Toad for Cloud Databases, a free SQL-based tool with the familiar look and feel of Toad, which enables users to use SQL(yes indeed SQL) with a set of  non-relational databases, including Hadoop (Hbase & Hive), Cassandra, MongoDB, SimpleDB, and Azure Table Services.

How does it work?

There are two key components to Toad for Cloud Databases:

  • Toad client: Use it to access Cloud/NoSQL databases via SQL statements.
  • Data Hub: It translates SQL statements submitted through the Toad client into a language understood by the Cloud database, and returns results in the familiar tabular row and column format.
Installation

You can download it from the following location(you’ll have to register first): http://toadworld.com/Freeware/ToadforCloudDatabasesFreeware/tabid/842/Default.aspx

Run the installer after downloading has completed.

Get started
  • Start the Toad for Cloud Databases client. Once the client is loaded you’ll see the Data Explorer on the left.

image

  • Right click on the Embedded Data Hub and choose Map Data Source…

image

  • The Map Data Source wizard is loaded. Specify a Data source name and choose the appropriate Data source type(we’ll choose Azure Table Services).

image

  • Specify the credentials to connect to your data source and click OK to complete this step.

image

  • The data source is added to the Tree view.

image

  • However before we can start doing something, we have to create a mapping first. Right click on the Mappable Objects and choose Map Multiple Tables…

image

  • The Map Tables screen is loaded. Select the Table you want to map and click OK.

image

  • The tool will create a Table for us and map all the found columns as can be seen in the Data Explorer Tree view.

image

  • Now we can right-click on the created table and start writing SQL by choosing Open SQL Editor.

image

  • A SQL Editor is opened and you can write and execute SQL statements.

image

  • That’s it!

Thursday, December 6, 2012

Team Foundation Server: Choosing a Process Template

One of the hardest parts of Team Foundation Server is choosing the right Process Template. The process template defines the set of work item types, queries, and reports that you will use to plan and track your project. Once you’ve created your Team Project, switching to a different Process Template is not an option. So you better choose right…
To help you through the process Microsoft provided a great MSDN article providing lot’s of information about the default templates.
It provides you some considerations to help you choose:
A comparison between the templates:
image
And even a nice overview of the different workflows:
image
Go check it out!

Wednesday, December 5, 2012

TFS Administration Tool 2.2 Released

The TFS Administration Tool has been updated to use the Team Explorer 2012 DLL’s. So you no longer need to install Team Explorer 2010 to use this tool.

Download TFS Administration Tool 2.2 (1.55 MB, MSI)

The TFS Administration Tool allows Team Foundation Server administrators to manage user permissions on all three platforms utilized by Team Foundation Server:

  1. Team Foundation Server,
  2. SharePoint, and
  3. SQL Server Reporting Services.
The tool also allows administrators to easily copy user permissions among team projects and to easily identify any missing permissions on any of the three platforms.

Tuesday, December 4, 2012

Team Foundation Server Source Control Explorer Extension

Last week when searching for an easy solution to delete some files from the TFS database, I found the following Visual Studio Extension: TFSSCExplorerExtension.

“TFSSCExplorerExtension (Team Foundation Server Source Control Explorer VS 2010 Extension) is  aVisual Studio 2010 Extension Package that adds new features to the TFS Source Control Explorer window for TFS 2010. ”

A separate release is available for Visual Studio 2012 here.

It offers the following features:

  • Move to Folder: Move support for multiple files.
  • Branch to Folder: Branch support for multiple files.
  • Merge from Sources: Select items to Merge.
  • File Icon Change: Branched files are shown with a different icon.
  • Drag & Drop: Adds drag & drop support between file list in the left side and folder tree in the right side.
  • Show/Hide deleted items: Quicker alternative then going to Tools – Options.
  • Destroy: Permanently removes files or folders from Source Control.

TFSSCExplorerExtension

Monday, December 3, 2012

ASP.NET MVC: Compile your views up front

For a project I’m doing we had to start a large refactoring round. Therefore it would be useful to get compiler errors on our ASP.NET MVC Views too. Otherwise we had to go through all the screens our self to detect problems.

Luckily ASP.NET MVC offers this feature out-of-the-box:

  1. Unload your ASP.NET MVC project by right right clicking the project on the solution explorer in VS and choosing unload project
  2. Right click on the csproj file name and choose Edit.
  3. Somewhere in the csproj file you’ll find the following line:
    <MvcBuildViews>false</MvcBuildViews>

  4. Change the MvcBuildViews value from false to true.

  5. Save the file and reload your project.

From this moment on the views are compiled too each time you build your project.