Friday, February 27, 2015

Microsoft Engineering Guidelines

Microsoft has put a list of Engineering Guidelines online. This document is their if you want to contribute to any of the open-sourced components that Microsoft has(and that’s a long list).

Now if you want to contribute some code or not, I can recommend to check these guidelines. There is a lot of useful information inside. (Always cool to look inside the head of the Microsoft software engineers Glimlach)

guidelines

Thursday, February 26, 2015

SQL Server Data Tools: Setup Continuous Integration for your Database Projects

In Visual Studio 2013, the SQL Server Data Tools are available out-of-the-box. They give you a new project template, the Database project, that allows you to manage your database objects and scripts in a structured way.

In this post I want to explain how you can enable continuous integration and automatically deploy your database changes each time you check-in some code.

Preparation

Before we start make sure that you created a database project and added some database objects. On your TFS build agent, the SQL Server Data Tools should also be installed. If you are using Visual Studio Online(like I will do) together with a hosted Build Controller, the Data Tools are already installed.(Here is the full list of installed components: http://listofsoftwareontfshostedbuildserver.azurewebsites.net/)

Add a Publish Profile

Open Visual Studio and load your Database Project. Once Visual Studio is ready, right-click on your Database Project and click on Publish…

image

The Publish Database window is loaded. Click on Edit… to add a connection string to the database where you want the database project published to. Afterwards click Save Profile As… to save the Publish profile and add it to your Database Project.

image

As we don’t want to deploy immediately, you can click on Cancel to close the window after the Publish profile is saved.

Creating a new Build Definition

Now everything is configured correctly, it’s time to open up Team Explorer(View –> Team Explorer).

image

Go to the Builds tab to add a new Build Definition.

image

Specify a name for your Build and move on to the Trigger tab.

image

Set the Trigger type to Continuous Integration and jump directly to the Build Defaults tab.

image

On the Build Defaults tab, select the Build Controller where the SQL Server Data Tools are installed. In my case I’m using Visual Studio Online, so I choose the Hosted Build Controller. I also choose to copy the build results to a Drops folder inside source control. Let’s move on to the Process tab.

image

On the Process tab, open up the Advanced section and paste the following line in the MSBuild Arguments field:

/t:build /t:publish /p:SqlPublishProfilePath=NorthwindDBProject.publish.xml

Replace the SqlPublishProfilePath value with the name you choose for your Publish Profile in the Database Project.

image

Save the Build definition, you are done! There are a lot of other things, you can configure, but by default, this should be enough.

Check-in and see what happens…

As a last step, do some changes inside your database project, check them into TFS, and look how your database is rolled out for you…

image

Wednesday, February 25, 2015

Microsoft Virtual Academy–Web Development Wednesdays

Microsoft Virtual Academy started a new initiative to get you going as a Web Developer: the Web Development Wednesdays. Every Wednesday they release a new web development training session where they explore platforms, frameworks, and everything somewhat related to web development.

image

From the site:

Web developers, do you want help navigating the modern world of web development? Join us for Web Wednesdays, an online web development training series, as we explore platforms, frameworks, and browsers to connect data and people. Entertaining and informative experts address scalability, design, and performance issues in each of these online web development courses. This training for web developers offers practical tips and explores real-world scenarios to help make your job easier. Don’t miss these opportunities to get the rest of the “web story”!

These sessions are offered for free, so no excuse for not signing up…

Tuesday, February 24, 2015

TFS Build Definition–Loading process template takes forever

While preparing a demo for a session I give later this week, I stumbled over the following problem:
I created a Build Definition for a build controller in TFS Online. When I try to edit the build definition(Right click –> Edit Build Definition…) and go to the Process tab, the only thing that shows is a ‘Preparing build definition environment’ message and an endless spinning wheel…
image
I found the issue on Connect but it was closed as ‘Not reproducable’ Bedroefde emoticon. Anyone with a solution?

Update: The workaround mentioned on the Connect site; repairing Visual Studio; solved the problem for me. 

Monday, February 23, 2015

Nice quote: The Legacy Code Dilemma

The Legacy Code Dilemma: When we change code, we should have tests in place. To put tests in place, we often have to change code.

Michael Feathersclip_image001

Friday, February 20, 2015

Impress your colleagues with your knowledge about…String.Intern

Sometimes when working with .NET you discover some hidden gems. Some of them very useful, other ones a little bit harder to find a good way to benefit from their functionality. One of those hidden gems that I discovered some days ago is String.Intern().

The String.Intern() method allows you to internalize string values explicitly. Ok, but what does this mean?

In a typical .NET application, the same string values are used over and over again. As this would end up with a lot of duplicated memory, .NET will allocate strings with unique content just once by using the string interning mechanism.

This leads to the question. As this interning is done for you, why do we need this method?  The thing is that only explicitly declared string literals are interned on the compile stage. The strings created at runtime are not checked for being already added to the string intern pool.

To solve this problem .NET offers two methods: String.Intern and String.IsInterned. If the string value passed to String.Intern is already in the pool, the method returns the reference to the string. Otherwise, the method adds the string to the pool and returns the reference to it. If you want to just check if a string is already interned, you should use the String.IsInterned method. It returns the reference to the string if its value is in the pool, or null of it isn’t.

Thursday, February 19, 2015

Securing your OWIN middleware through Security Headers

If you like at the OWASP site, you’ll find a while list of common security-related HTTP headers that every web application should implement. These headers are an essential part of building a secure web application.

If you are too lazy to click on the link, here is the full list:

There are multiple ways to add these security headers to you application. You can configure IIS to include them, add some extra ASP.NET (MVC) configuration or you can build some OWIN middleware to add these headers to every HTTP request.

If you decide to use OWIN, be aware that most of the work is already done for you. On GitHub I found the SecurityHeadersMiddleware project which implements most of the headers mentioned above.

Get started

The easiest way to get started is to install the package using NuGet: Install-Package SecurityHeadersMiddleware

Inside your startup.cs class, you can now add some code to enable the headers:

More information can be found here.

Wednesday, February 18, 2015

Simplify OpenXML editing

Working with OpenXML is not that easy. Although very powerful, the XML structure is complex especially when you want to programmatically edit existing OpenXML documents.

One tool that can help you to make this job somewhat easier are the PowerTools for Open XML. It contains a wide range of features and guidance for accomplishing various tasks using the Open XML SDK.

While browsing through the code, a colleague discovered the following hidden gem inside the PowerTools: the MarkupSimplifier class. This class allows you to cleanup an OpenXML document before you start editing it. The end result after the cleanup operation is a simplified XML structure that is easier to manipulate using the OpenXML SDK.

Tuesday, February 17, 2015

Angular 1.3 $pending

Inside an Angular 1.3 sample, I noticed the usage of ‘$pending’. Strange, never seen that object before. Let’s find out where it’s useful!

‘$pending’ finds it use together with the new $asyncValidator pipeline. The $asyncValidator pipeline contains validation rules that will typically be rules that needs server-side logic to make a decision. As long as the async validation rule promise isn’t resolved $pending will return true. This can be useful to give the users a visual indication while the validation rule is executing.

Monday, February 16, 2015

Angular: jQuery events not firing

On a web application we were building I had a strange issue. A jQuery widget was working as expected until I also tried to use it inside an Angular application. The widget that was responsible to expand or collapse a panel, refused to work. Clicking on the panel header had no effect anymore.

This was one of those situations where the solution is obvious afterwards, but I had no clue at first what was going on Verwarde emoticon.

When looking inside the widget, I found code similar to this:

Nothing wrong with that code you should say! Unless you realize that this code is only executed when the DOM is ready. The HTML views that are loaded by Angular are loaded afterwards when the document ready already fired. So the initialization logic for the widget is not executed for new elements loaded by Angular.

To fix it, I updated the widget to use the (newer) jQuery event delegation syntax:

So simple, once you know it…

Friday, February 13, 2015

Angular.js IntelliSense in Visual Studio

Today Visual Studio already offers you Angular.js IntelliSense. However it’s functionality is limited to a standard list of keywords and doesn’t recognize your own directives, controllers, etc… This is because the JavaScript editor doesn’t understand the way that Angular dynamically loads object references when your app is launched. John Bledsoe, a member of the Visual Studio community, created a great extension that helps the Visual Studio editor with this. By simulating the execution of your Angular application as you write your code, it provides a significantly better IntelliSense experience.

AngularIntelliSense

How to use it…

To get started, you need to install the AngularJS extension for Visual Studio. To do this, download the angular.intellisense.js file and place it in the Program Files (x86)\Microsoft Visual Studio 12.0\JavaScript\References folder.

More information about this extension can be found here: http://blogs.msdn.com/b/visualstudio/archive/2015/02/05/using-angularjs-in-visual-studio-2013.aspx

Thursday, February 12, 2015

CSS: Highlight current row and column

A while ago, we had  to write some functionality to highlight the current row and column for the current active cell inside an HTML table. I didn’t pick up the work item but a colleague implemented the functionality. I don’t know the exact implementation details anymore, but I do know that it involved a large amount of custom JavaScript and CSS code(at least a lot more than I expected).

Recently I found another clean solution(with far less code) to implement this functionality on css-tricks.

image

No idea, if I ever get a similar question, but just in case, I post the link here…

Wednesday, February 11, 2015

Unit Testing Examples

If you tried to write Unit Tests before, you know it can be hard. If you are looking for a little guidance, check the Unit Testing Examples and Labs on Github created by Dan Hellem.

It covers the very basics to more in-depth materials such as dependency injection, mocking, and TDD. Here is the full list of covered topics:

  1. MSTest Unit Testing Basics
  2. XUnit
  3. Mocking
  4. Mocking Frameworks
  5. Dependency Injection
  6. TDD
  7. Data Driven Tests
  8. SSDT (Testing Stored Procedures)
  9. Exceptions
  10. Testing your JavaScript
  11. Jasmine
  12. Web Api Rest Services

Tuesday, February 10, 2015

Microsoft Azure Cloud Roadmap

With the continuous flow of new functionality that is announced, in preview, in GA(General Availability), and so on… provided by the Azure team, it is impossible to keep up-to-date. When customers ask me if feature X is already available on Azure, my default answer was ‘I have to look it up, I’ll come back to you’. And than I had to spend a long time searching through the Azure Portal, blog posts, forums,… before I could return to my customer with a good(at least better than ‘I don’t know’) answer.

Recently, Microsoft made my job as a consultant a little bit easier. They created the Cloud Platform Roadmap website

The Cloud Platform roadmap provides a snapshot of what we’re working on in the Cloud Platform business. Use the roadmap to find out what we’ve recently made generally available, released into public preview, are still developing and testing, or are no longer developing.

In a nice and structured way, all features are shown grouped by the following topics:

  • Cloud infrastructure
  • Enterprise Mobility
  • Data management and analytics
  • Application development
  • Internet of Things

and statuses:

  • Recently Available
  • Public Preview
  • In Development
  • Canceled

Read the official announcement here: http://blogs.technet.com/b/server-cloud/archive/2015/01/30/increasing-visibility-for-our-customers-announcing-the-cloud-platform-roadmap-site.aspx

And again, my life just became a little bit easier Glimlach

Monday, February 9, 2015

GitHub Training

Interested in using GitHub? But you don’t know where to start. The Roslyn team put their internal training, done by Jared Parson, online.

Friday, February 6, 2015

Pace.js–A great progress bar for all your web applications

Pace.js gives you a beautiful progress indicator for your page load and AJAX navigation.

What makes it even better is you don’t need write any code to get it working. Pace will hook into your browser events and detect progress automatically. Can it be any easier?

image

More information can be found here: http://github.hubspot.com/pace/

Thursday, February 5, 2015

Angular.js: re-use your validation messages

One really handy trick with Angular's ng-messages module is the ability to re-use messages. Instead of specifying the list with possible validation messages over and over again for every form field, just create one HTML template and load that:

In case you don’t want a generic validation message or want to add extra validation messages, this remains possible as well:

Wednesday, February 4, 2015

Angular.js caching your $http results

Angular.js has built-in support for caching. Just set cache to true when passing the $http options:

If you want more control you can use the $cacheFactory:

 

Tuesday, February 3, 2015

Pickles–Generate documentation from your SpecFlow tests

I’m a big fan of SpecFlow, a BDD framework that allows you to write your tests as executable specifications. A colleague mentioned another tool, Pickles, that generates documentation in a variety of formats from your specifications. Time to give it a try…

Installing Pickles

The easiest way to integrate Pickles in your project is to download it through NuGet. So let’s do that first:

Install-Package Pickles

This will download the Pickles Powershell DLL and load it in the Package Manager shell.

image

Running Pickles from Powershell

Let’s write some Powershell code to test Pickles. First initialize some variables to simplify the readability:

And now invoke the Pickle-Features command:

You should see similar results like below:

image

Let’s have a look at the generated results. You get a nice website which shows you all the features and their test results:

image

image

Specflow also supports other formats then HTML. Here is the full list:

  • HTML
  • DHTML (javascript-enabled, search capabilities)
  • JSON
  • Word
  • Excel

More information

For more information, have a look at the following links:

Monday, February 2, 2015

Free eBook: The developer’s guide to the new .NET

2015 will be an important year for the .NET framework. What started end 2014 with .NET going Open Source, will continue in 2015 with the release of Roslyn, C# 6.0, .NET on Mac and much more…

Michael Crump and Sam Basu released a free (registration required) eBook “The Developer’s Guide to the new .NET”. This book gives you a quick and easy-to-read tour through all the new and upcoming changes in .NET and its ecosystem.

image