Steal Focus

Wednesday, 8 February 2012

A minimal SignalR example

SignalR is an “async signaling library for .NET to help build real-time, multi-user interactive web applications”.

And its very cool. A minimal example…

Add the “SignalR” NuGet package to a web application:

Install-Package SignalR

The HTML:

<html>
<head>
</head>
<body>
<script src="../Scripts/jquery-1.6.4.js"></script>
<script src="../Scripts/jquery.signalR.js"></script>
<script src="../signalr/hubs"></script>
<form id="form1" runat="server">
<div>
<script type="text/javascript">
var chat;

$(function () {
// Created proxy
chat = $.connection.myChat;

// Assign a function to be called by the server
chat.addMessage = onAddMessage;

// Register a function with the button click
$("#broadcast").click(onBroadcast);

// Start the connection
$.connection.hub.start();
});

function onAddMessage(message) {
// Add the message to the list
$('#messages').append('<li>' + message + '</li>');
}

function onBroadcast() {
// Call the chat method on the server
chat.send($('#message').val());
}
</script>
<input type="text" id="message" />
<input type="button" id="broadcast" />
<ul id="messages"></ul>
</div>
</form>
</body>
</html>

The code (C#):

    using SignalR.Hubs;

public class MyChat : Hub
{
public void Send(string message)
{
// Call the addMessage method on all clients
Clients.addMessage(message);
}
}

And that is it.

Now you have a real-time chat/message application. View the page in multiple browsers and see all the client receive all the messages in real-time.


Friday, 9 December 2011

The only Windows Azure Pricing Calculator you will ever need

I wrote this to cost up a project: https://skydrive.live.com/view.aspx?cid=0DE849CA9FB5B198&resid=DE849CA9FB5B198%21704

For UK currency.

Unlike every single other calculator out there it allows you to…

  • Specify a profile for 5 environments (each profile can differ in number/size of Compute Instances etc):
    • Integration Test
    • System Test
    • User Acceptance Test
    • Pre-Production
    • Production
  • Specify how many hours (per week) you need your Compute Instances for (you might be happy to tear down your hosted services each night – if you’re not using them, why pay?)

Monthly and yearly totals shown.


Friday, 4 November 2011

Windows Azure Pricing

Pay as you go: http://www.microsoft.com/windowsazure/offers/MS-AZR-0003P

What qualifies as a transaction in Windows Azure Storage (you pay per transaction): http://blogs.msdn.com/b/windowsazurestorage/archive/2010/07/09/understanding-windows-azure-storage-billing-bandwidth-transactions-and-capacity.aspx

MSDN Benefits for Windows Azure: http://www.microsoft.com/windowsazure/msdn-benefits/


Thursday, 3 November 2011

Windows Azure and operational cost reduction

One of the things that strikes me the most about using Windows Azure (or most cloud solutions) is the savings you can make with your test environments.

In Windows Azure world, your on-going cost is for your Compute instances (what you deploy your applications to) and your storage. Whether you are using the application or not, you are paying money for your Compute instances and storage to exist. Other costs (Access Control, CDN etc) you pay per use or transaction.

So if you have a system test or user acceptance test environment that you are not using, you can simply delete the Compute instances and any storage artefacts. Then you don’t pay for them.

Contrast this will your on premise applications. You probably have multiple test environments for different projects and those are sitting there, costing you money whether you use them or not.

Some people suggest that Windows Azure (and some other cloud services are not that cheap). I disagree. Let’s say I need a system test environment for 5 days a month. A “Large” Compute instance (4 x 1.6GHz, 7GB RAM, 1000GB storage) costs $0.48/hour. Well 5 days at 8 hours a day (most people don’t work 24/7) costs me $19.20 (this includes the operating system license). I can script the creation of my compute instances and other artefacts very simply, so automatically spinning up or shutting down assets on demand.

So, a pretty meaty server for a system test environment on Windows Azure costs me $19.20 for the 5 days per month I want to use it.

How much is your on premise hardware costing to run for a whole month?


Tuesday, 1 November 2011

PowerShell, MSBuild and 64-bit platforms

If you call PowerShell from MSBuild on a 64-bit platform, you will often get unexpected errors. One such error is as follows:

No snap-ins have been registered for windows powershell version 2

The probable cause is that the MSBuild executable you are running is not 64-bit. On 64-bit platforms you should execute MSBuild from the following location:

%SystemDrive%\Windows\Microsoft.NET\Framework64\v4.0.30319\msbuild.exe

Depending on how/what you have installed, your Start Menu shortcuts might be pointing to the 32-bit version.


Monday, 31 October 2011

Elegantly testing for a PowerShell Snap-In

This PowerShell script tries to load the WAPPSCmdlets snap-in, fails silently if the loading of the snap-in fails (if it isn’t installed), advises the user and exits from the script.

if ((Get-PSSnapin | ?{$_.Name -eq "WAPPSCmdlets"}) -eq $null)
{
  Add-PSSnapin WAPPSCmdlets -erroraction SilentlyContinue
  $SnapIn = GET-PSSnapIn WAPPSCmdlets -erroraction SilentlyContinue
  if ($SnapIn -eq $null)
  {
    Write-Error "To run this script the 'Windows Azure Platform PowerShell Cmdlets' are required."
    Write-Error "Please download from '
http://wappowershell.codeplex.com/' and install as a PowerShell Snap-in (not as a Module)."
    Exit
  }
}

I’m testing for “WAPPSCmdlets” but you could test for any PowerShell Snap-in.

Simples (if you don’t get it).


Saturday, 22 October 2011

Increasing quotas on Windows Azure

By default, your subscription quotas on Windows Azure are as follows:

  • Cores – 20
  • Hosted Services – 6
  • Storage – 5

To increase these you need to submit a request: https://support.microsoft.com/oas/default.aspx?prid=13185&st=1

Options:

  • Support topic – “Service Deployment and Developer Portal”
  • Sub-topic – “Quota increase”

Thursday, 29 September 2011

Error messages

This is a new one.

500

If you see the monkeys, let me know.


Wednesday, 28 September 2011

Assembly versioning (for .NET)

Like most people, I version my assemblies during the continuous integration build. This is achieved by generating a class file (I call it “AssemblyInfoCommon.cs”) during the build. It looks like this:

using System;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

[assembly: AssemblyCompany("Acme")]
[assembly: AssemblyConfiguration("Branch.Release.1.0.xxx.xxx Debug")]
[assembly: AssemblyCopyright("Copyright © Acme 2011")]
[assembly: AssemblyFileVersion("1.0.xxx.xxx")]
[assembly: AssemblyInformationalVersion("1.0.xxx.xxx")]
[assembly: AssemblyProduct("PetShop")]
[assembly: AssemblyTrademark("Acme")]
[assembly: AssemblyVersion("1.0.xxx.xxx")]


Where…




  • “1.0.xxx.xxx” is the version number (we’ll come to the “xxx” value later")


  • The “AssemblyConfiguration” attribute breaks down as follows:

    • “Branch” is constant.


    • “Release” will vary depending on what you call your branches


    • “Debug” is the Visual Studio Solution configuration so will typically be “Debug” as shown or “Release”.




  • The company name, copyright notice and year all all passed in from the build script as variables.


  • The product name is whatever the project is called.



This is all pretty straight forward so far. However, down the years I’ve had problems with a strategy for the version number.



In the .NET world, the version number breaks down as follows:




[major].[minor].[revision].[build]




See MSDN.



Originally, the my version numbers broke down as follows:




1.0.yMMdd.x




Where “major” and “minor” are configured manually (these never automatically increment).



The “revision” number breaks down as follows:




  • “y” is the last digit of the current year. For 2011, this is “1”.


  • “MM” is obviously the month.


  • “yy” like wise for the day.



The “build” number represents the number of builds today, so the first build of the day takes “1”, the second “2” etc.



The would give you the following build numbers (I’m choosing old dates for a reason…):




  • 1.0.10926.1 – the first build on 26th September 2001


  • 1.0.11231.3 – the third build on 31st December 2001


  • 1.0.20101.4 – the fourth build on 1st January 2002



This worked pretty well for a number of years. Unfortunately, there is a constraint on the components of the version number that did not become apparent until 1st January 2006.



The first build number for 1st January 2007 was (in theory) “x.y.70101.0”. Unfortunately each component of the version number is an “Int32”. The largest value for an Int32 is “65534”, “70101” is bigger than this. Queue me getting build failure notification e-mails while on a beach in Thailand on New Year’s day, which was nice.



Since then, I’ve wrestled with a couple of different strategies but none ever really worked. The one I got most mileage out of was the same as before for Major, Minor and Build but had a different strategy for the Revision. I used the day of the year in combination with the year. So the Revision for…




  • 31st January 2011 would be “1031” (the 31st day of the year)


  • 2nd February 2011 would be “1032” (the 32nd day of the year)


  • 31st December 2011 would be “1365” (the 365th day of the year)


  • 1st January 2012 would be “2001” (the 1st day of the year)



This is problematic for two reasons:




  • You have to do maths to work out when a version was built.


  • Years ending in 0 (2010, 2020) cause problems because of leading zeros get dropped by the compiler. So 1.0.0001.0 (1st Jan 2010) would become 1.0.1.0 which is confusing.



Recently I’ve found a new strategy which works pretty well. The problem with the first strategy is fitting revision numbers for “high” years into an Int32, the problem with the second one is leading zeros. This third strategy overcomes this and breaks down as follows:




1.0.yyMM.ddxx




Where “major” and “minor” are as before.



The “revision” number breaks down as follows:




  • “yy” is the current year. For 2011, this is “11”.


  • “MM” is again the month.



The “build” number is as follows:




  • “dd” is the day.


  • “xx” is the build number of the day.



Examples:




  • 1.0.1109.2601 = 26/09/2011, 1st build of the day


  • 1.0.9912.3199 = 31/12/2099, 99th build of the day


  • 1.0.1201.0101 = 01/01/2012, 1st build of the day


  • 1.0.1112.3199 = 31/12/2011, 99th build of the day



There’s one caveat – best to not have more than 99 builds in one day but that is a highly unlikely scenario.


Tuesday, 27 September 2011

BizTalk Message Box Viewer

The “BizTalk Message Box Viewer” is a nifty little tool that complements the BizTalk Best Practices Analyser very well:

http://blogs.technet.com/b/jpierauc/archive/2007/12/18/msgboxviewer.aspx


Blog Archive

About Me