Friday, 28 October 2011

TPL DataFlow C#

The new DataFlow library can build up pipelines for our data to flow through.

Perhaps you have a series of processes a file must go through in a defined sequence:

  1. Encrypt
  2. Compress
  3. FTP
  4. Archive

DataFlow allows for easy manipulation of concurrency, asynchronicity and build up of our data flow pipelines.

In this simple example a number is posted into the pipeline, to be transformed by doubling it.  It can then be passed to the ActionBlock for output to screen.

You can download the TPL DataFlow CTP from Microsoft:
http://msdn.microsoft.com/en-us/devlabs/gg585582

Metro Futures

Thursday, 27 October 2011

Configuring a Web Server to host Silverlight Apps

To configure your web server to host your silverlight application, you’ll need to add the following MIME types to your web server:

MIME type Extension
application/xaml+xml .xaml
application/x-silverlight-app .xap

And to setup the server for WPF and ClickOnce applications:

MIME type Extension
application/manifest .manifest
application/x-ms-application .application
application/x-ms-xbap .xbap
application/octet-stream .deploy
application/vnd.ms-xpsdocument .xps

Agile Principles

Requirement Gathering

User Story

image

As a, I want, So that / Given, When, Then

image

Estimating Time

Story points

Not based on time but rather a number relative to previous size/complexity of an item.

image

Planning

image

image

SCRUM

image

Roles

image

image

image

Scrum Artifacts

image

image

image

image

image

image

image

image

image

Scrum Ceremonies

image

image

image

image

image

image

image

Activities

image

image

image

image

Tools

AgileZen

image

image

image

image

Grasshopper Project Management (if using Jira)

image

image

image

image

Friday, 21 October 2011

QUnit: TDD with JavaScript

image

QUnit is a TDD framework that allows developers to write unit tests against their JavaScript libraries and run them in the browser or against a CI server. 

For this blog article I’ll be showing you how to setup your dev machine to write and run the tests.

What shall we Unit Test today?

For this example I am going to create some unit tests around a popular jQuery pub/sub plugin, which is available here: https://github.com/phiggins42/bloody-jquery-plugins

The plugin API is very simple and allows the developer to: 

  • subscribe to an topic
  • unsubscribe from a topic
  • publish a topic

My Folder and File Layout for QUnit

image

When you download the source code to my example you’ll see the following files:

core Folder Contains the two core libraries to run QUnit:  QUnit.js and QUnit.css
(JQuery is also required, online file used)
source Folder Contains the JavaScript you will be testing
tests Folder The unit tests
TestRunner.html Folder Open in the browser to run the tests

This layout is purely my preference but helps me keep a nice structure to my tests and CI build.

The Test Runner

The Tests

The first couple of lines are just const variables for topics and can be ignored. 

module("Pub/Sub Tests"); gives the tests a grouping (see test output image at the top of the blog article.

test("test name”, function () { … }); is the unit test name and code.

expect(1); states the number of expected assertions within the test.  If this number is not realised the test will fail.

ok(error === null, 'No error occurred'); and equal(count, 2, 'callback was fired twice'); are examples of assertions.

Links

My example source code: http://stevenhollidge.com/blog-source-code/QUnit.zip

QUnit source: https://github.com/jquery/qunit

QUnit docs: http://docs.jquery.com/Qunit

Wednesday, 19 October 2011

HTML5 Server Side Events

Overview

Server-Sent Events (SSE) is a standard describing how servers can initiate data transmission towards clients once an initial client connection has been established.

It is commonly used to send message updates or continuous data streams to a browser client and designed to enhance native, cross-browser streaming through a JavaScript API called EventSource, through which a client requests a particular URL in order to receive an event stream.

This means the client can receive a one way fire hose of data from the server for such scenarios as new FX rates, stock prices, new message received, etc.

But I thought we had Web Sockets for this?  Yes, HTML5 does provide Web Sockets but that is for full duplex (bi-directional) data transfer whereas SSE can be used for one way communication from server to client.

image

In our simple example

  • The client automatically registers for Server Sent Events, setting Id to the current time (in JavaScript)
  • Every 5 seconds the server pushes event data to the client
  • The data, made up of three parts Id, Detail and Timestamp is displayed on the page.
  • A message counter is incremented for each message received.
  • The Server terminates the connection after 10 seconds (after 3 messages)
  • The cycle starts with the client registering for events.

 

Points of Interest

Notice how in the screenshot only two HTTP GETs were sent from the client to the server data URI (stream.php), one for each connection that was made.  The connection is kept open whilst the 3 events/messages are pushed the client.

Data format

In our example we are using JSON data format within the Event-Stream data format. We also need to set the Content Type of the event to “text/event-stream”.

To be able to set the HTTP header content type, we’ll be using a simple php script:

HTML Source

You can view the page online:  http://stevenhollidge.com/html5demos/server-sent-events/

Monday, 17 October 2011

jQuery Pub/Sub

image

Source Code

jQuery pub/sub plugin by Peter Higgins (dante@dojotoolkit.org)

Sunday, 16 October 2011

Memcached C#

image

Memcached is a distributed object memory caching system, acting as an in-memory key-value store for small chunks of arbitrary data (strings, objects) from results of database calls, API calls, or page rendering.

Downloads

Client library source and demo for C#:  http://sourceforge.net/projects/memcacheddotnet/

Client library binary for C#:  http://stevenhollidge.com/blog-source-code/memcached-windows-client-binary.zip

Server runtime for Windows:  http://stevenhollidge.com/blog-source-code/memcached-windows-server.zip

How to start the Server

To run the server with 2 Gb of memory (2000Mb), copy the files from the above server download into C:\Program Files\memcached directory and execute the following command:

image

Simple client code example

Benchmark with simple example: key=“key:n”, value=”MyData”

Example benchmarks with 1 million sets and gets, the source code can be found within the client library download above:

image