Wednesday, January 28, 2015

Getting Started with Setting up a SignalR Service

SignalR Service Class
The first step is to create a class that inherits from Microsoft.AspNet.SignalR.Hub and create a service method in this class with a return value of void.

This class is the SignalR service that the JavaScript code calls through either a generated proxy or some other JavaScript code (i.e. manually generated calls to the server). Note that the generated proxy makes your callers (both on the client and the server) code much simpler. In this blog post, it's assumed that one will use the generated proxy though there are ways to code against the service without a generated proxy.

Three main areas are:
  1. Client side JavaScript proxy file is generated
  2. Server side methods
  3. Client side JavaScript code to be called from the server side
One you created your SignalR service class, you can view the generated proxy in the browser. To view this JavaScript navigate to http://localhost/signalr/hubs.

To use this proxy file make a references
  • jQuery
  • Generated proxy i.e. /signalr/hubs.
Please keep in mind that the generated proxy is not a physical file, but dynamically generated on the fly.

Client side
To a make SignalR service connections, the following must be achieved
  1. Reference the generated proxy
  2. Create a connection object - client side
  3. Register a callback event handler for the server side to call
Establish the connection through calling the 'start()' method on the connection object. This starts a connection and follows ups with a call to the server side service method. The code looks similar to:

$.connection.yourHub.start().done( function() {

A client side event handler for service methods to call. Client side code looks similar to:

$.connection.yourHub.client.updateMyEntity = function (response) {
    // js code

Server side
The service method callback to the client, for example, with an update of the progress. This code similar to:


Note the server side callback method name and the JavaScript method names.


Wednesday, January 21, 2015

MVC's relation to N-tier architecture (Oldie but goodie)

In a nutshell, they are not the same. The MVC framework mostly forms the presentation layer.


Could either be the same as the value objects or mapped objects (using such tools as Automapper).

Renders the model data in the presentation objects.

A liaison between the business layer and the view. This thin layer passes the conditions of the requests (querystring or posted values) to the business layer. Once the model (or value objects) are given back from the business layer, the controller passes them to the view for rendering.

N-tier Architecture

Business Layer
This is always the most complex of the tiers and contains business specific logic to execute.
It mostly communicates to the Data layer to populate value objects and pass them back to the presentation layer (through the controller)

Data Layer
This layer is talked to by the business layer but it talks to the database. In some cases contains some logic in the form of either stored procedures or view (in a non-No-SQL sense).

Presentation Layer
If implementing with an MVC framework, then it works with all three parts of the MVC framework.

Thursday, February 20, 2014

Discover your SQL server database table list, count and row count

After restoring some backup of SQL database file, there were dizzying number of tables. Not 20. Not even 50 but close to 20 x 50 tables. I wanted to know the magnitude of the complexity of the database that I’d dealing with.

First I checked for any data constraint issues. Please refer to a previous blog post to do exactly this. Fortunately, none was uncovered in this particular case.

And second I wanted to get a sense for how much data is the database initially populated OOTB when a customer installs this particular software i.e. how many rows of data are in each table of the database.

Friday, February 07, 2014

Getting Started with Fluent Migrator and resolve the listmigrations task issue

In this blog post, the steps it takes to setup a sample FluentMigrator migration classes is explained and in addition the solution to the issue with listmigrations task parameter with FluentMigrator version

1. Create a Class Library Application

2. Add a Reference to the FluentMigrator Assembly
In the Package Manager Console, installed FluentMigrator
                Install-Package FluentMigrator –version
                This made a reference to “FluentMigrator.dll” in this project

Friday, January 31, 2014

Uncovering Data Constraint Issues in Your Database

A project of ours included inheriting legacy code and database. The codebase used a mixture of two ORMs: Entity Framework and NHibernate. Through refactoring, we've unified the data access technology to use NHibernate/Fluent NHibernate however it wasn't until the usage of FluentMigrator that I discovered the underlying data suffered from some unchecked constraints/referential integrity issues.

In one of our user stories we set out to trim our data down and provide the following set of data for our integration test project to include:
-          Static Data
-          Configuration Data
-          Dynamic Data