Friday, May 30, 2014

Techorama: Evolvable Application Development with MongoDB

The slides and the code for our session at Techorama are online:

Slides

Code

https://github.com/wullemsb/DemoTechoramaMongoDb

It was a great conference and I had a lot of fun! I’m already counting down to next year…

Monday, May 26, 2014

Speaking at Techorama

This week will be a quiet week on my blog. I’m attending Techorama, a new developer conference here in Belgium.

Even better I’m also giving a session together with my colleague Gerd Teniers.  If you are at Techorama and want to learn something about MongoDB, feel free to join us…

I'm speaking at Techorama

Friday, May 23, 2014

Entity Framework Migrations: No context type was found in the assembly 'MyProject'

After creating an initial version of my data model using EF Code First, it was time to enable the Code-First migrations. So I opened up the Package Manager console and typed the following command:

Enable-Migrations

Doing that had no effect, instead I got the following error message back:

No context type was found in the assembly 'MyProject'

The problem was that the project where I created the DbContext class was not the same as the project where I wanted to store the migrations. The EF guys were smart and already provided a solution for this. By using the –ContextProjectName option, you can specify the project name(!), this one is important so not the namespace or full name of the context class, where Migrations should search for a context:

Enable-Migrations -ContextProjectName "MyProject.DAL"

Thursday, May 22, 2014

Angular.js: Track selected item by id not by reference

Using Angular.js I created a form where a user could select a value. The selected value is then bound to a property on the controller.

Here is the corresponding code:

The problem is that the moment I leave the screen and come back the dropdown no longer has an item selected. When searching through the Angular.js documentation I found the following important note:

image

When leaving the screen and coming back, the data is fetched again from the server, so the selected application object is no longer pointing to the same object as the application objects in the list.

To fix this you can use the ‘track by’ option inside the binding expression:

image

Wednesday, May 21, 2014

NuGet: Uninstall a package without removing all packages that depend upon it

In my post from yesterday I mentioned that I wanted to constraint the jQuery version to 1.* inside my application. The problem was that my team was a little bit to eager and already updated to jQuery version 2.*. As a lot of packages were depending on the jQuery NuGet package, I couldn’t just tell NuGet to delete the package:

Uninstall-Package jQuery

This call would fail complaining that I have packages that depend upon it. You can still delete the package if you want to by adding the –Force command line option:

Uninstall-Package jQuery –Force

This will ignore the dependencies and just remove the jQuery NuGet package from your solution.

Tuesday, May 20, 2014

NuGet: prevent developers from upgrading to a newer version

I’m working on an Angular.js Single Page Application right now. One of the requirements is that we still have to support IE8. Therefore it’s important that we stay on the 1.* version number for jQuery because the 2.* release dropped support for IE8.

We are using NuGet and the jQuery Nuget package to keep our dependencies under control. The problem is that when we open up NuGet, jQuery was in the list of packages to update. As developers we all want to work with the latest and greatest, so I had to make sure that no one in my team accidently updated jQuery to 2.*.

You can fix this by executing following steps:

  • Open the packages.config file inside your project
  • Add an allowed versions attribute to the jQuery package
    • <package id="jQuery" version="1.9.1" allowedVersions="[1.9.1,2)" />
  • This tells NuGet that we allow all versions starting from 1.9.1 until 2(version 2 NOT included).

That’s it!

Monday, May 19, 2014

New release of the TFS Planning and Disaster Recovery Avoidance Guide

The Visual Studio ALM Rangers team keeps bringing us high quality content around ALM and Team Foundation Server. This week they released a new version of the ‘TFS Planning and Disaster Recovery Avoidance Guide’ (pfew, what a mouthful).

imageThis guidance delivers practical and scenario based guidance for the implementation of Team Foundation Server (TFS). It guides you through the decisions whether to have one or more Team Foundation Servers, one or more Team Project Collections, one or more Team Projects and one or more Teams, based on scenarios and implications of each decision. It concludes with disaster recovery planning, frequently asked questions and a collection of real world reference stories.”

Friday, May 16, 2014

Angular.js: Try/Catch/Finally using the Q module

Similar to exception handling in .NET the Q promise module inside Angular.js supports a try/catch/finally construct. However as ‘finally’ is a reserved keyword in JavaScript, you have to use the indexer to access the finally function:

Thursday, May 15, 2014

Angular.js: optional route parameters

The route module in Angular.js supports optional parameters. You can specify that a parameter is optional by adding a ‘?’ after the route parameter:

maintenanceApp.config(['$routeProvider', function ($routeProvider) {

$routeProvider

    .when('/', { templateUrl: '/Apps/MaintenanceApp/partials/applications.html' })

            .when('/applications/', { templateUrl: '/Apps/MaintenanceApp/partials/applications.html' })

            .when('/environments/', { templateUrl: '/Apps/MaintenanceApp/partials/environments.html' })

            .when('/editApplication/:id?', { templateUrl: '/Apps/MaintenanceApp/partials/editApplication.html' })

            .when('/editEnvironment/:id?', { templateUrl: '/Apps/MaintenanceApp/partials/editEnvironment.html' })

    .otherwise({ redirectTo: '/' });

    }]);

Wednesday, May 14, 2014

Enable Windows Authentication in ASP.NET MVC

The simplest way to enable Windows Authentication inside an ASP.NET MVC application is by executing one of the following options:

Option 1 - Configure the web.config.

Set the authentication mode to Windows and disable anonymous access inside the web.config:

Option 2 – Configure IIS Express.

Enable Windows Authentication Enabled in IIS Express. (If you want you can also disable Anonymous authentication).

clip_image002

Tuesday, May 13, 2014

Log objects using SeriLog

After using Enterprise Library Logging Application Block for a long time, it’s time to move on. At the moment I’m investigating SeriLog, a promising logging library for .NET.

From the site:

Why Serilog?

Like other logging libraries for .NET, Serilog provides diagnostic logging to files, the console, and so-on. It is easy to set up, has a clean API, and is portable between recent .NET platforms.

Unlike other logging libraries for .NET, Serilog is built with structured log data in mind. Parameters passed along with log messages are not destructively rendered into a text format. Instead, they're preserved as structured data that can be written in document form to a NoSQL data store.

One of the biggest advantages of SeriLog is the support for structured logging and the integration with multiple data stores(‘Sinks’ as they are called in SeriLog).

SeriLog allows you to log anonymous types. It will print out all properties of the type.

If you execute the following statement:

this is what is saved inside the log file:

2014-05-09 17:08:54.249 +02:00 [Information] In my bowl I have "{ FruitId = 1, FruitName = Test }"

But if you try to do the same thing for a normal class it doesn’t work.

If you execute the following statement:

this is what is saved inside the log file:

2014-05-09 17:09:35.009 +02:00 [Information] In my bowl I have "WebApplication1.Controllers.HomeController+Fruit"

It is still possible to log the properties instead, but you have to add a “@” inside the log statement before the log parameter:

Monday, May 12, 2014

Finally: migrate your Team Foundation Server On Premise to Visual Studio Online

The team from OpsHub, the creators of the (commercially available) OpsHub Integration Manager, released the OpsHub Visual Studio Online Migration Utility.  This finally introduces a solution to migrate your on premise TFS data to TFS online.

OpsHub Visual Studio Online Migration utility helps customers wanting to migrate the most commonly requested data from an on-premises Team Foundation Server to their Visual Studio Online account.  It is designed for basic migration scenarios to migrate history of version control changesets, work items, test cases, and test results.

Features:
  • Easy to use and helps user make intelligent need based decision.
  • One-way migration from on-premises Team Foundation Server to Visual Studio Online.
  • Change history is preserved during migration with original details included in work item revision history and version control changeset comments.
  • Entities supported include :
    • Version Control
    • Work Item Tracking
    • Test Cases
    • Test Results
  • Mapping between on-premises Active Directory accounts & Workgroup user accounts in Team Foundation Server with Microsoft Accounts (formerly known as Windows Live IDs) used in Visual Studio Online.

I’ll have to try it myself, but it certainly looks promising…

Friday, May 9, 2014

The Visual Studio Installer project is back!

With the release of Visual Studio 2012, Microsoft decided to remove support for the Visual Studio setup project template. Instead you got a template for InstallShield Limited Edition (ISLE) as an alternative.

Although rather limited, the Visual Studio setup project template was very useful for small installer projects. So lot’s of people complained… and Microsoft listened!

Last month they released a preview of the Visual Studio Installer Projects Extension. This preview release reintroduces support for Visual Studio Installer projects in Visual Studio 2013. You can download the extension from the Visual Studio Gallery.

Visual Studio Gallery

The extension does not introduce any new features but gives you the same functionality that you currently have in Visual Studio 2010.

Thursday, May 8, 2014

TFS 2013 installation error: TF400069 You must install either SQL Server Analysis Services version 11.0

Rolling out a Team Foundation Server environment is always an adventure. Everytime I discover some new stuff. Last week at a customer I was setting up a new Team Foundation Server 2013 server when I got the following error message:

TF400069: You must install either SQL Server Analysis Services version 11.0 or the SQL Server Client Tools.

clip_image002

Did I forgot to install something? I went through the SQL Server Installation wizard(slow!) to see that I had indeed the SQL Server Client Tools installed. Just in case, I removed and reinstalled them… no difference. I had no clue so I even tried to install the SQL Server Analysis Services but even that made no difference.

It took me some time to figure out what I did wrong. Let’s have a second look at the error message (and especially look at the highlighted text):

TF400069: You must install either SQL Server Analysis Services version 11.0 or the SQL Server Client Tools.

Team Foundation Server 2013 requires at least SQL Server 2012 with SP1, I had installed the SQL Server 2008 R2 version Verwarde emoticon.

Wednesday, May 7, 2014

ID1038: The AudienceRestrictionCondition was not valid because the specified Audience is not present in AudienceUris.

I’m in the process of building my own STS implementation(don’t ask why). While testing an Active Federation scenario, I got into trouble and ended with the following error message:

ID1038: The AudienceRestrictionCondition was not valid because the specified Audience is not present in AudienceUris.

Aah, you have to love WIF and it’s wonderful set of error messages... Glimlach

The problem was that I forgot to add an audienceUri in my client config:

Tuesday, May 6, 2014

Visual Studio solution files backward compatible?

Last week a colleague asked me if it was possible to open a Visual Studio 2012 solution file in Visual Studio 2010?

The answer is  “it depends’' Glimlach:

Starting from VS 2010 SP1 you can switch between Visual Studio versions without having to go through the annoying conversion/migration process. However this is only true if you are using a compatible framework version and that all the project types in your solution are supported.

Monday, May 5, 2014

Bringing some of the goodness of Angular.js to Knockout

I’ve been using Knockout for some time now, but more recently I started using Angular.js. And I have to admit it there are some really nice features in Angular that I would love to have in Knockout as well.

I was planning to write some extensions myself but then I discovered Knockout.Punches which introduces some enhanced binding syntax for Knockout.

One of the things I like in Angular is the concept of filters:

This will take the ‘name’ value from your bound ViewModel, returns only the first 20 characters and convert the result to uppercase.

And this is how you can do it using Knockout.Punches:

Have a look at the documentation for some of the other nice features it offers...

Friday, May 2, 2014

Asp.NET MVC BundleConfig: {version} string

One of the neat features inside the ASP.NET Optimization library is the support for a {version} string. Before you had to update your BundleConfig.cs each time that you upgraded one of your included JavaScript/CSS libraries.  The{version} placeholder tells the bundler to look for a string in the form of N[.N[.N]] and pick the file with the highest numbers.

You can see this feature in action by looking at the BundleConfig you get out-of-the-box when creating a new ASP.NET MVC application:

This will load the latest JQuery file that can be found inside my Scripts folder:

image

You can do the same thing for Modernizr or any other library that uses the same versioning pattern.

There is only one thing missing in this feature; it only works when the version is part of the filename not of a folder. For example, when you use the Kendo UI libraries you’ll see that they don’t have a version number in every file but instead have the version number on the folder level.  Unfortunately this doesn’t work with the {version} number feature and you still have to update the references yourself:

image

image