Friday, January 30, 2015

Angular.js: Using inline templates

When using Angular.js, your view content doesn’t have to be separate HTML files. Instead you can perfectly use inline HTML templates. Here is a quick sample how to do this:

Thursday, January 29, 2015

ASP.NET MVC EditorFor bug

I think I need Anger Management therapy after losing waaaaay to much time looking at a problem inside ASP.NET MVC.

What was the problem?

I created a nice ASP.NET MVC EditorTemplate to use the Kendo UI NumericTextBox for decimal fields. Here is the corresponding Razor file:

But for an unknown reason MVC wasn’t picking up the correct EditorTemplate. Here is the original code:

I had to update the code to include the EditorTemplate type to get it working:

Smells like a bug to me!

Wednesday, January 28, 2015

Eurelia–The next generation version of Durandal

After leaving the Angular Team, Rob Eisenberg continued his effort in building the greatest next generation JavaScript client framework. Yesterday he finally shared his work with the rest of the world and announced Aurelia.

image

Here are some of the features as mentioned on the Aurelia website:

  • Forward thinking: Written with ES6 and ES7 but transpiles to today’s browsers
  • Modern architecture: Multiple small replaceable components
  • Two-Way databinding: Performant two-way binding to any object using adaptive techniques
  • Extensible HTML: Read as ‘Angular Directives’ Glimlach
  • Routing & UI Composition: The already great Durandal router on steroids
  • Broad Language Support: Written with TypeScript, AtScript, CoffeeScript,… in mind

And here an introduction video:

Introducing Aurelia from EisenbergEffect on Vimeo.

As a big fan of Durandal(and Caliburn), I’m really interested in the results. I know what to look into the upcoming weeks…

Tuesday, January 27, 2015

OpenXML: Apply password protection to your Word documents

If you are using OpenXML to generate Word documents and want to make the generated documents readonly(and protect them with a password), here is a useful code snippet:

Monday, January 26, 2015

:-( Helios failed to start

For a project we are comparing multiple web server options in terms of performance. The project will be using ASP.NET Web API, but the web server will be either

  • IIS(using the ASP.NET pipeline)
  • IIS(using Microsoft Helios)
  • Selfhosting(using the OWIN selfhost)
  • Or something else(don’t know what)

I downloaded the required(pre-release) NuGet packages, configured my web project and started the application. But what I saw, was not what I expected:

Helios

I was welcomed by the following error message:

:(

Helios failed to start.

The ApplicationStart method threw an exception. Detailed exception information is below.

System.TypeInitializationException: The type initializer for 'Microsoft.Owin.Host.IIS.Security.Algorithms' threw an exception. ---> System.Security.Cryptography.CryptographicException: Unknown error "-1073741275".

at Microsoft.Owin.Host.IIS.Security.Algorithms.CreateSP800108AlgorithmHandle()

at Microsoft.Owin.Host.IIS.Security.Algorithms..cctor()

--- End of inner exception stack trace ---

at Microsoft.Owin.Host.IIS.Security.DataProtection.DataProtectionProvider.CreateImpl(Byte* masterKey, Int32 masterKeyLengthInBytes)

at Microsoft.Owin.Host.IIS.Security.DataProtection.DataProtectionProvider.CreateNew()

at Microsoft.Owin.Host.IIS.Security.DataProtection.HeliosDataProtectionProvider.CreateFactory(IHttpApplication httpApplication, Boolean& requiresApplicationIsolation)

at Microsoft.Owin.Host.IIS.Security.DataProtection.HeliosDataProtectionProvider.CreateDataProtectionProvider(IHttpApplication httpApplication)

at Microsoft.Owin.Host.IIS.OwinApplicationBase.ApplicationStart(IHttpApplication application)

at Microsoft.AspNet.Loader.IIS.HttpApplicationBase.InvokeApplicationStart(IHttpApplication application)

My bad! I didn’t took a look at the prerequisites. You need at least Windows 8 or Windows Server 2012 to use Helios on top of IIS. Although a better error message would have been useful, I have learned that reading the documentation could be helpful Glimlach

Friday, January 23, 2015

Azure WebJobs: Log location

A colleague asked me where he could find the logs of Azure WebJobs he configured inside an Azure Website.

For every Azure Website you create a Kudu dashboard exist. To get to this website browse to https://{site name}.scm.azurewebsites.net (in other words, add .scm in front of your Azure website name).

image

Click on the Debug console menu item and choose the CMD option. The Kudu Remote Execution Console is loaded.

image

You can now browse to the correct log location either by using the command line or by clicking through the folders at the top. Log files for the Azure Webjobs can be found under d:\home\data\jobs

image

More information about Azure Website logging can be found at:

Thursday, January 22, 2015

Angular.js: Return a promise that is already resolved

I have an Angular service that either should return an existing object or call a webservice and load some data. To have a consistent client API I want to use a promise in both cases.

It’s not very hard to do this using Angular:

Wednesday, January 21, 2015

Bootstrap Progress bar

Today I lost some time searching why I couldn’t get the Bootstrap Progress bar working.

The problem is that the sample on the Bootstrap site(http://getbootstrap.com/) isn’t up-to-date for the latest Bootstrap version(Bootstrap 3.3.1). Here is the sample code as of today:

image

Instead the correct code should look like this:

Tuesday, January 20, 2015

Restier: Bringing WCF Data Services and Web API OData together

Microsoft is working on a new framework called Restier:

RESTier is a RESTful API development framework for building standardized, OData V4 based REST services on .NET. It can be seen as a middle-ware on top of Web API OData. RESTier combines the convenience and simplicity of WCF Data Services alongside the flexibility and extensibility of Web API OData.

Similar to a WCF Data Service it exposes your Data Model through a REST service. 

Get started.
  • Create a new MVC application
  • Add an Entity Framework Code First context
  • Include the Microsoft.Restier NuGet Package(don’t forget to set Include prerelease)

image

  • Create a Domain class that wraps your DbContext:
  • Add a Web Api controller inheriting from ODataDomainController that wraps the Domain class:
  • As a last step add an extra route to the WebApiConfig file:
  • If you run the application and browse to /api/northwind, you can see the available entity sets:

image

Monday, January 19, 2015

Interested in a coding challenge? Check www.codehunt.com

The guys from Microsoft Research who created Pex, also created www.codehunt.com.

You are an experimental application known as a CODE HUNTER.

You, along with other code hunters, have been sent into a top-secret computer system to find, restore, and capture as many code fragments as possible.

Your progress, along with your fellow code hunters, will be tracked. Good luck

CodeHunt.com is a coding game that asks you to update code fragments so that all tests succeed. The more efficient your code, the more points you score. Behind the scenes it is using the Smart Unit Tests feature. Certainly a good and fun way to improve your coding skills.

Ready to beat my record? :-)

image

Friday, January 16, 2015

MSDN Subscription now offers access to a range of Pluralsight courses

If you have a MSDN subscription today, I have some good news for you. Starting from this year, subscribers receive a 12-month Pluralsight training benefit as part of its MSDN subscription. The number of courses included in this benefit depend on the type of MSDN subscription. Here is a sample:

CourseCatalog

Information how to activate this benefit can be found here; http://blogs.msmvps.com/deborahk/msdn-now-includes-pluralsight-courses/.

Thursday, January 15, 2015

ASP.NET MVC file download: correctly set mime type

In an MVC application, we are offering the functionality to download files. This is easy thanks to the built-in FileResult class.

The only caveat is that we have to support a wide range of file formats. To make the browser react correctly it’s important to set the correct MIME type in the response. Before ASP.NET 4.5 you had to build your own list of mappings between a file extension and the related MIME type. Luckily, in .NET 4.5, this is no longer required.  The MimeMapping class exposes a public static method called GetMimeMapping which takes in a file name (or extension) and returns the appropriate MIME type:

Wednesday, January 14, 2015

Angular.js ng-options – bind to key instead of object

In an Angular.js application we are building I had the following situation:

I have an array of option objects containing a label and a value that is used as input for a select list. On my controller I want to bind to the selected value (and not to the selected object!).

Here is the controller:

First I had the following code in  the view:

The above code resulted in the selectedValue set to the complete option object and not to the option.value property.

To fix it, I had to update the view code to the following:

Tuesday, January 13, 2015

End-to-end testing with Angular: Protractor

One of the things that makes Angular.js such a great framework, is the integrated support for testing. To make it even better the Angular team also offers Protractor, an end-to-end test framework for AngularJS applications. Protractor is using Selenium behind the scenes and runs tests against your application in a real browser.

image

To learn more about Protractor, you can try the following tutorial: http://angular.github.io/protractor/#/tutorial

Remark: The only thing I find annoying(as a .NET developer) is that I had to install the Java Development Kit (JDK) to get Selenium up & running. If you know a workaround, please let me know…

Monday, January 12, 2015

Performance Analysis of Logs (PAL) Tool

Last week, when investigating some performance issues, I stumbled over the following tool: Performance Analysis of Logs (PAL) Tool.

From the site:

Ever have a performance problem, but don't know what performance counters to collect or how to analyze them? The PAL (Performance Analysis of Logs) tool is a powerful tool that reads in a performance monitor counter log and analyzes it using known thresholds.

Features

  • Thresholds files for most of the major Microsoft products such as IIS, MOSS, SQL Server, BizTalk, Exchange, and Active Directory.
  • An easy to use GUI interface which makes creating batch files for the PAL.ps1 script.
  • A GUI editor for creating or editing your own threshold files.
  • Creates an HTML based report for ease of copy/pasting into other applications.
  • Analyzes performance counter logs for thresholds using thresholds that change their criteria based on the computer's role or hardware specs.

image

image

Friday, January 9, 2015

ASP.NET Web API Request Batching

Most applications I’m building today are using a kind of Web API. This works great, but leads to chatty interfaces, requiring a  large number of requests to get all the required data. In situations where the API is only for internal usage and you don’t want to share it with other applications, your application can benefit from a technique called ‘Request Batching’.

Remark: Be aware that Batch requests are not REST-compliant. So if you are creating a public API stop reading… Glimlach

What is it?

Request batching combines multiple API requests into a single POST request. HTTP provides this out-of-the-box using a special content type called Multipart. On server-side, requests are unpacked and dispatched to the appropriate API methods. All responses are packed together and sent back to the client as a single HTTP response. The nice thing is that it is already supported by ASP.NET web API and you don’t need a lot of extra code to get it working.

Enable Request Batching in ASP.NET Web API

The only thing you need to do to get it working inside ASP.NET Web API is defining an extra route:

Inside the route you can use the  DefaultHttpBatchHandler or create your own custom implementation:

In the above sample I changed the ExecutionOrder property. By setting this to non-sequential, API requests are executed in parallel.

From the client, you can consume this Batch API like this:

Thursday, January 8, 2015

Mobile Development Platform Performance Comparison

When choosing a development platform for building Mobile applications, performance is always one of the discussion points pro- or contra a specific technology. A lot of people claim that technology X is faster than technology Y without real numbers to proof their point. I did some tests myself and had mixed experiences using Cordova, Xamarin and Native Mobile development.
Last week I noticed this blog post by Kevin Ford: http://magenic.com/Blog/PostId/67/mobile-development-platform-performance. Kevin took the time to create a formal comparison between
  • Native (Objective-C 64 bit and Java)
  • Cordova (Multi-Device Hybrid Apps) using Intel's App Framework for the UI
  • Classic Xamarin (64 bit unified beta for iOS)
  • Xamarin.Forms (64 bit unified beta for iOS with beta version of Xamarin.Forms, note latest version of the unified API in the beta/alpha channels could not be used as it is not supported by Xamarin.Forms)
Go check out the full post for all the details, but some things that are worth to mention:
  • Xamarin is really fast, sometimes even faster than the native platform(e.g. Objective-C)
  • Xamarin.Forms has little overhead and gives almost the same numbers as for the classic Xamarin libraries
  • Cordova is a lot slower for CPU bound work but can keep up for service calls and serialization
Great post!

Remark: A colleague mentioned another performance comparison with similar conclusions; https://msdn.microsoft.com/en-us/library/system.string.isinterned(v=vs.110).aspx

Wednesday, January 7, 2015

Learning Reactive Extensions(RX) by example: ReactiveTrader

You are interested in learning Reactive Extensions(http://rx.codeplex.com/)? But you don’t know where to start or you don’t see a practical use case?

Have a look at the ReactiveTrader application created by the guys from Adaptive.

From the site:

Reactive Trader is a client-server application demonstrating some of the problems needing to be dealt with when building reactive, or event driven, user interfaces. It was initially built as a demonstration application for a presentation we gave at ReactConf 2014.

What makes this example really nice is the fact that it exists for multiple platforms like HTML5, iOS, WPF,…

image

Tuesday, January 6, 2015

Angular.js style guide: using an activate() method inside your controller

There are lots of opinions about how to write good Angular code. One of the best style guides out there is the one created by John Papa available at https://github.com/johnpapa/angularjs-styleguide.

It contains a large list of great tips about naming guidelines, application structure, testing, exception handling, and so on…

One advice that I started to implement recently is the usage of ‘Controller Activation Promises’. It solves the problem where you have your start-up logic scattered around across the controller. It places all start-up logic in a consistent place.

How do you this? Simple, create an activate() function and put all your start-up logic inside:

Monday, January 5, 2015

Organizing a Hackaton

Last year, our company organized their first(internal) hackaton. It was a great success, with little sleep but lots of fun. So this year the hackaton will be back, but bigger and better.

If you are interested in organizing your own hackaton, certainly check out the following information: