Friday, August 29, 2014

Microsoft Azure ebook: Building Cloud Apps with Microsoft Azure

The summer holiday is almost over, but still some time left to read at least one more ebook.

Why not  end with a cloud related book, especially when it’s free?!

I can recommend ‘Building Cloud Apps with Microsoft Azure’. It covers the full process of building and deploying an application in a ‘cloud-optimized’ way.

From the introduction:

This ebook walks you through a patterns-based approach to building real-world cloud solutions. The patterns apply to the development process as well as to architecture and coding practices.
The content is based on a presentation developed by Scott Guthrie and delivered by him at the Norwegian Developers Conference (NDC) in June of 2013 (part 1, part 2), and at Microsoft Tech Ed Australia in September 2013 (part 1, part 2). Many others updated and augmented the content while transitioning it from video to written form.

image

 

You can download a completely free PDF, Mobi or ePub version of the ebook:

Thursday, August 28, 2014

Azure Websites–Staged deployment

One advantage that the traditional Azure Cloud Services had over Azure Websites was the support for VIP swap. This allowed you to switch your development and production environment with one click. You could deploy your application first to the test environment, check if everything is working as expected and then switch to production. The only difference between the 2 environments is that one is using the ‘real’ url of your cloud service where the other is using an auto generated GUID.

If you wanted a similar experience using Azure Websites, you had to deploy to multiple sites. This has now changed thanks to the introduction of Deployment Slots.

From the documentation:

The option to create site slots for Standard mode sites running on Microsoft Azure Web Sites enables a staged deployment workflow. Create development or staging site slots for each default production site (which now becomes a production slot) and swap these slots with no down time. Staged deployment is invaluable for the following scenarios:

  • Validating before deployment - After you deploy content or configuration to a staging site slot, you can validate changes before swapping these changes to production.

  • Building and integrating site content - You can incrementally add content updates to your staging deployment slot, and then swap the deployment slot into production when your updates are completed.

  • Rolling back a production site - If the changes swapped into production are not as you expected, you can swap the original content back to production right away.

Microsoft Azure warms up all instances of the source site slot before the swap to production, eliminating cold starts when you deploy content. The traffic redirection is seamless, and no requests are dropped as a result of swap operations. Four deployment slots in addition to the default production slot are supported per Standard web site.

Each deployment slot has its own publish settings, so the deployment experience in Visual Studio using Web Deploy remains similar(and also Source Control Integration is still an option).

image

More information here: http://azure.microsoft.com/en-us/documentation/articles/web-sites-staged-publishing/

Wednesday, August 27, 2014

Angular.js: Using the baked-in ‘extend’ function

Inheritance in JavaScript remains a complex beast. Even when using Angular.js, you sooner or later will need some inheritance hierarchy. Your best friend to implement an inheritance hierarchy in Angular.js is the ‘extend’ functionExtend automatically applies the properties and functions from the base ‘class’ to the child ‘class’. Important to notice is that you’ll use ‘extend’ on the object prototype; this will ensure that the properties and functions are part of any instance that is created. Angular will also bind the properties and functions so this refers to the instance itself.

Extend can be called multiple times and you can pass a collection of objects if you want to. This enables your components to inherit from multiple ‘base classes’.

Tuesday, August 26, 2014

A safer way to upgrade your NuGet packages

Updating all your NuGet packages for a solution is easy thanks to the ‘Update-Package’ command or through the ‘Update All’ option when using the UI. However it’s always a tricky practice as a lot of things can go wrong. Worst case you end up with a set of incompatible updates causing breaking changes,  strange behavior and unexpected errors. Fun!

So most of the time I try to avoid any NuGet update unless it’s really necessary. Until I discovered a new option for the Update-Package command:

Update-Package -Safe

The “Safe” switch will only upgrade Revisions and will not touch Major and Minor versions. So if all your NuGet packages follow the semantic versioning rules, this is a great solution avoiding lots of problems.

If only I knew about this option before…

Monday, August 25, 2014

Farewell Windows Azure Training Kit, welcome Azure Readiness content

For years, I’ve been using the Windows Azure Training Kit. It contained a large list of Hands-on-Labs, Presentations and Demos. The Training kit is history now and replaced by the Azure Readiness content.

So if you are looking for some good Azure resources, don’t search for Azure Training Kit but have a look at the Azure Readiness content instead.

image

The Azure Readiness Content provides a set of presentations and demos designed to help learn the latest Microsoft Azure features and services.

Friday, August 15, 2014

Team Foundation Server: Change profile picture

In Team Foundation Server, you can set a picture for your user profile. This picture is shown at different locations inside the TFS Web Access. As long as you don’t set a picture, you only get a boring icon.

For example the Team members overview looks like this on the Overview page of your TFS project:

image

Let’s change this!

  • Navigate to the Web Access url of the Team project that has the User Profiles you want to set.
  • Navigate to the Administration page by clicking on the Wheel icon in the upper right corner.

image

  • Click on the Security tab

image

  • Select Users from the left panel

image

  • Select the User Profile you want to edit.
  • Click on the image on the top right hand corner to edit the image.

image

  • In the Profile Image dialog, upload your image and Save Changes.


image

  • That’s it!

If we now look at the Team Members again, you’ll see:

image

Remark: This change will be applied to all your Team projects.

Another way to get there:

  • Click on your name in the right corner of the page

image

  • Select My profile

image

  • Click on Change picture

Thursday, August 14, 2014

Programmatically creating an Excel file without using OpenXML(or Excel Interop)

With the switch to the Excel XLSX format, it became possible to create Excel files using the new XML based OpenXML format. Great news for us developers as we no longer needed Excel Interop or 3th party components to generate our XML files programmatically.

However, the world ain’t perfect yet, as the OpenXML format is very rich and complex. So it’s still not easy to generate an XML file without any help or tooling. Luckily for us there is the OpenXML SDK which helps a lot when creating these Excel files.

But did you know there is a simpler alternative which doesn’t even require the OpenXML SDK? Using a simple XML is enough. Let’s have a look…

  • First create a new MVC application
  • Inside the App_Data folder add the following XML template:
  • Let’s now create an action method that reads the XML template, replaces the placeholder token with some data and send the results to the browser:
  • Run the application and browse to the /home/downloadexcel url
  • A download dialog will be shown and once you open the file in Excel you’ll see something like:

image

Wednesday, August 13, 2014

Impress your colleagues with your knowledge about... ThreadLocal

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 the ThreadLocal class.

For a long time I’m using the [ThreadStatic] attribute in .NET. It allows you in an easy way to create static variables scoped on a per thread basis. Using it is easy, it is simply a matter of decorating a static field with the [ThreadStatic] attribute:

As mentioned by Jon Skeet, using ThreadStatic has some disadvantages:

  • The variable must be static
  • You have to call the initialization logic yourself
  • Limited PCL support

.NET 4.5 introduces another class that solves the same problem: ThreadLocal.

It offers the same functionality as the ThreadStatic attribute but does not have its disadvantages:

  • The variable doesn’t have to be static
  • You can specify an initialization delegate to be executed on first use in any particular thread (similar in the way you initialize Lazy<T>)
  • The intent is more clear

Tuesday, August 12, 2014

Free NHibernate ebook released

The Succinctly series keeps growing. Short after the release of the Entity Framework Code First book, we now have NHibernate Succinctly from the same author.

Grab you copy…

Monday, August 11, 2014

Running PHP Codesniffer on Windows

For a customer I have to review some PHP code.I always use a heterogeneous set of tools to get the job done. This time I wanted to use PHP Codesniffer(next to some other tools like PHP Depend,…) The thing is, I didn’t do any PHP development for a while. So I had to configure my machine to be able to run PHP code again.

Installing PHP on Windows

The easiest thing to get going is use WebMatrix. This already provides you with a nice IDE to run any kind of PHP application. Now before we can use it with PHP, you should install PHP for IIS Express available through the Web Platform Installer.

image

Remark: The first time you open up a PHP site in WebMatrix, it will ask to install PHP for IIS Express for you. 

Installing PEAR on Windows

After installing PHP, it’s time to install PEAR. PEAR is a package manager similar to NPM for node.js and NuGet for .NET.

Here are the steps:

  • Go to http://pear.php.net/go-pear.phar to download go-pear.phar and copy it to the PHP installation directory(C:\Program Files (x86)\IIS Express\PHP\v5.3 in our case).
  • Open a command prompt with administrative permissions
  • Go to the php directory
  • Begin the PEAR installation by executing following command
    • php go-pear.phar
Installing PHP Codesniffer

Last step is easy, by using PEAR, installing PHP Codesniffer only requires one extra command:

  • pear install PHP_CodeSniffer

Friday, August 8, 2014

Microsoft Azure: How to configure a SQL Server VM on Azure?

Microsoft Azure gives you a preprovisioned Virtual Machine with SQL Server installed. So getting a SQL Server as a PaaS solution is really easy in Azure. What you have to be aware of is that some extra steps are required before you can start using your SQL Server instance.

You have to:

  • Create a TCP endpoint on your VM with a public port of your choice and port 1433(the default port that SQL server uses) as the private port
  • Add an exception in the firewall configuration of the VM for incoming traffic on port 1433
  • Configure SQL Server to mixed mode configuration so you can use a SQL login to connect to the database
  • Create a SQL login on the database
  • And of course, don’t forget to test it Glimlach

More information and a detailed walkthrough can be found here: http://azure.microsoft.com/en-us/documentation/articles/virtual-machines-provision-sql-server/

Connecting to a SQL Server virtual machine

Thursday, August 7, 2014

Angular.js: Directive execution order

Last week, a colleague asked me if there is a way to control the order in which your Angular.js Directives get executed.

Of course you can! Every directive has a ‘priority’ property. When there are multiple directives defined on a single DOM, the priority is used to sort the directives before their compile functions get called. Directives with greater numerical priority are compiled first. The default priority is 0.

An example:

Wednesday, August 6, 2014

Entity Framework Code First ebook

I blogged about the Succinctly list of ebooks before. Since then the list kept growing and growing. Recently a new book was added about Entity Framework Code First. If you are new to Entity Framework, this is a good (and short) starter.

Go check it out!

Tuesday, August 5, 2014

SQL Server: Execute rights on all stored procedures in a database

I’m currently working on an application deployment. One of the things I had to configure was the database security settings. To minimize the attack surface I created a SQL Server user with only the necessary rights(and nothing more). The annoying things is that the application I have to deploy is full of stored procedures.

I started with giving the SQL login ‘EXECUTE’ permissions on every individual stored procedure but this was really cumbersome. There should be a better way…

And of course there is, use the following SQL command to grant a user ‘EXECUTE’ permissions on all stored procedures(even ones you add later):

Monday, August 4, 2014

Why Agile is failing in large enterprises…

Today, almost every customer I visit has jumped on the Agile train. They are working in ‘sprints’(with changing lengths), they do ‘daily standups’(but they only do it every week), they use user stories(but don’t talk to the customer), and so on…

Does this mean that Agile is failing? I don’t know, I think you can still make it a success. How? Have a look at the following presentation by Mike CottMeyer for inspiration:

Also, don’t forget to checkout his blog: http://www.leadingagile.com/blog/. Good stuff!

Friday, August 1, 2014

SQL Server: How much of your data is NULL?

For a project I’m working on, I ‘inherited’ an existing database. Most of the columns where nullable so almost every field in our Entity Framework model was of type Nullable<T>. As the data itself is used to do calculations, all these extra null checks and ‘.Value’ everywhere made our code a lot harder to read and understand.

However while looking through the data in the database, I had the feeling that most columns should actually be not nullable. But I had to be 100% sure before I could make the switch.

Based on the following blog post(http://blogs.msdn.com/b/samlester/archive/2012/09/22/tsql-solve-it-your-way-finding-the-percentage-of-null-values-for-each-column-in-a-table.aspx), I created a small SQL script that returns the percentage of NULL values for all columns in a table:

This returns the following result:

image

By doing this, I could easily identify columns that possibly should be not nullable.