Nancy, ASP.Net vNext, VS2014 & Azure

By now we know of Microsoft’s plans for the next version of ASP.Net and they’ve turned it on its head and from the looks of it, its goooooood!

Here is a blog post from Scott Hanselman introducing ASP.Net vNext. There are introductory and deep dive videos available for your perusal which are also well worth a watch.

The TL;DR is ASP.Net vNext will take heavy influence from Node.js by using Owin to wire up all the app dependencies and middleware. It will also remove *.csproj files and use a project.json file similar to Node’s package.json and use NuGet to reference the application’s dependencies. It also takes inspiration from Node and Nancy’s approach requiring you to opt-in to dependencies rather that traditionally having everything but the kitchen sink. It also takes influence from Nancy via built in dependency injection and Mono support. Microsoft announced they will run all their vNext tests against Mono builds ensuring all their code is compatible for cross platform deployments.

Here’s a tweet direct from the horses mouth albeit with a typo .

vNext influenced by Node/Nancy

Read more...

Modifying the bash prompt and adding Git completion to terminal

At work we use Git and I use Console2 to control my terminal envrionments eg/Git Bash, Powershell, Dos and when using Git I can type part type a git command press tab and it will auto complete the command or offer suggestions to commands. By default on OSX this behaviour is not present and it frustrated me enough to go and find out how to enable that behaviour.

Fire up your terminal and type in this command:

curl https://raw.githubusercontent.com/git/git/master/contrib/completion/git-completion.bash -o ~/.git-completion.bash

This will download a git completion file into your home folder to a hidden file called git-completion.bash.

If the file ~/.bash_profile does not already exist create it with the following command.

touch ~/.bash_profile

Now open it and paste this in:

if [ -f ~/.git-completion.bash ]; then . ~/.git-completion.bash; fi

Now if you type a git command and press tab, BOOM!, you have auto complete for Git!

Read more...

Introducing Owin.StatelessAuth with Nancy/Angular demo

If you’re writing an API, current thinking is to provide a token in the Authorization header for your app to validate when the request comes in. I have used the Nancy.Authentication.Stateless package in the past for my APIs and even have a demo of it here if you’re interested (there are more Nancy demos at http://samples.nancyfx.org). This is a great package and does a great job but what if one day you want to use SignalR v2 that uses OWIN and you want to validate not just requests to your Nancy app but also the SignalR requests? You’re going to need to validate requests as they come in before they get to SignalR or Nancy.

For those of you who are not quite up to date or unsure what OWIN is let me try and give you the tl:dr, no doubt others may say its something slightly different. Imagine you are asked to create a ASP.Net MVC 3 app (ignore the fact that that person needs a slap) so you fire up Visual Studio and create the app. So what has it done? Its created an app that runs on IIS and all requests come straight into your app.

Read more...

Using NodeJS and FTP with Promises

I’ve played with node in the past but as of the new year I decided to try and make a more concerted effort to get stuck into node properly. I decided to go back to the beginning to try and get a better appreciation for the language so read “JavaScript: The Good Parts by Douglas Crockford”. I found that exercise fulfilling and resulted in a few light bulb moments that made some dots join up so I’d recommend reading it if you haven’t already.

Real World App

As I stated earlier I have already played with node in the past using Express and have read quite a bit on node and read many examples but I wanted to write a non-web app as I felt this would give me a better opportunity to get to grips with the language and Node. Using Express allows you to get up and running very quickly without to much head scratching so I felt a standalone script would give me more exposure to things.

Read more...

Unit Testing with SqlException

So after a nice Christmas break I get to some code that needs some unit testing around a try/catch. Something similar to this:

try
{
    myService.DoSomethingThatMightTakeALongTime();
}
catch (EntityCommandExecutionException ex)
{
    var exception = ex.InnerException as SqlException;
    if (exception != null)
    {
        if (exception.Number == -2)
        {
            //Do something special
        }
    }
}

Read more...

Using SQL Server with node.js

I like to keep eyes and ears open for new technologies and methodologies in order to become a better developer and I’d heard about edge.js many months ago but made a mental note of it and waved it goodbye. edge.js lets you have two-way communication between node and C# libraries. When I first looked at it I thought that sounded a bit hacky, I’ve spent my time communicating with COM libraries in Delphi and OCX libraries with C# and didn’t like it so I felt this was pretty much the same thing. A long time passed and I was writing a console based Windows app as a service and had wondererd whether I could quickly port it to node.

I was discussing with a colleague about using node at work and that we needed something seperate and small just to try it out and see how the whole developement process with it worked. As the database that this app needed to communicate with was MSSQL I looked into a library on NPM that would communicate with MSSQL and maybe act as an ORM. There was a Microsoft lib that seemed untouched and reading the comments on the issues list on Github it didnt favour too well. There were libraries that would communicate with MySQL & PostgresSQL but not MSSQL. In my search I came across edge.js again. It had 2 samples, one that used edge-sql and one that used ScriptCS so in laymans terms, one that used a precompiled dll and one that used a C# script that was executed at runtime.

Read more...

Octopus XML Transformation in Services

We use Octopus Deploy at work and its a superb tool for deploying your applications whether they be websites or *.exes.

One of the great things it also provides is the ability to use Microsoft’s Transformation process for config files. However, when deploying a exe application its a bit trickier than a website. Unfortunately the documentation doesn’t mention the steps needed to get this working so read on!

Typically a web application will have web.config and a web.Release.config as well as other derivations you may use. Octopus also supports web.[Environment].config.

Read more...

Using Git to update YouTrack via TeamCity

This post is mainly a reminder for me as I keep forgetting the command in Git to integrate commits to YouTrack items. YouTrack uses TeamCity to get the information about the commits and then scans the commit comment for a YouTrack item id and any commands that it can apply such as item status or time spent on said item. There is some documentation here but its not the greatest in terms of clarity and I’ve spoken to Hadi Hariri from JetBrains about improving this so hopefully they’re working on it.

Read more...

Running Mocha tests within Sublime Text

I spend most of my day in Visual Studio with lots of the goodies an IDE can offer. One of them being able to run your tests from a keystroke.

In a bid to expand my mind I’m working on a little project that is made up of JS entirely so I’ve dug out Sublime Text. It has lots of plugins that are very handy, especially Sublime-HTMLPrettify which will tidy your HTML, CSS & JS for you.

When writing tests for JS there are many libraries you can use but I’ve chosen Mocha for now. The one thing I couldn’t work out was to run my tests within Sublime Text until now.

Build System

Sublime allows you to have build systems a bit like an IDE so you can tell it what to do when you invoke it via cmd+B.

To get Mocha to run we need to create a new build system. To do this click Tools - Build System - New Build System and paste in the below:

Read more...

Blogging with Markdown & Deploying via Git - Introducing Sandra.Snow

There are many markdown blogging engines out there such as Calepin, Scriptogram and even WordPress allows you to write blog posts in Markdown but Sandra.Snow tries to add something different. Firstly, it is written in .Net and Nancy, secondly its a static blog generator and finally it supports Git deployment.

Even if you don’t want to use Git deployment you can use FTP, its a great tool. To write your blog post in Markdown you need a custom header in your file so it knows some information about your post.

---
layout: post
category: Azure
title: Setting up a ServiceStack Service
---

It then parses this information along with your Markdown into its engine, uses a Markdown view engine to convert the file content into HTML, assign model properties based on the header and creates a HTML file using the model via a Razor viewengine.

The “layout” refers to the Razor file it uses to render the final HTML file. This allows you to style your pages and blog posts whichever way you’d prefer. These “layout” files should exist in the “_layouts” folder for your site template. The site template is a set of files and folders that Sandra.Snow uses to produce the final static website.

The “category” or “categories” property, you can use both for singular or multiple comma-seperated values that refer to the category/categories of your blog post.

The “title” should hopefully be self explanatory!

You can optionally add an author and email properties to override the global config settings for example, if you wanted to allow guest author blog posts. There is also an optional metadescription property you can use for SEO.

Read more...