Friday, July 30, 2010
 
   
 
Welcome to my site

First let me say thanks for stopping by my site. My name is David Hanson-Graville and I am a IT consultant working in the UK. Let me make it clear, I am passionate about technology and specifically .net and its various forms. I've programmed in a range of langages, but I can say, I am now at my happiest when coding with c#. I hope my blog is an enjoyable & educational read and please feel free to email me at David.Hanson@OnTheBlog.net if you have any questions. 

OnTheBlog Minimize
Author: David Hanson Created: Wed, 02 Jan 2008 20:28:49 GMT
All things .net, wpf, XAML, C#, Workflow Foundation and many more.

Cosmic Crashes
By David Hanson on Tue, 29 Apr 2008 19:51:56 GMT

 

I was catching up on some podcasts during my drive to work recently and came across an interesting topic on the BBC's Digital Planet podcast. The discussion was regarding the “impact” cosmic rays can have on our desktop computers and more importantly very expensive grid platforms such as IBM’s Blue Gene. Computer crashes can be annoyng to the average user but on grid platforms running simulations that require accurate data they can be very costly. During the podcast they had interviewed with an Intel researcher (who's name I have forgotten sorry) who was discussing his strategies for counter acting the effects these highly energetic particles can have.

Before I outline his proposal it’s probably worth explaining some rudimentary physics.
 
What is a cosmic ray?
Answer: A cosmic ray is a particle with mass greater than zero that has been been accelerated to a speed that is approaching the speed of light.
 
How does it get that fast?
Answer: A range of cosmic events can cause this but let’s just say for this blog, a star exploded millions of years ago and that it is this explosion that caused the cosmic ray.
 
I heard that most cosmic rays just pass right through us.. How come?
Answer: Well thanks to Mr Einstein we know that with increased mass comes an exponential increase in energy in order to accelerate the matter towards light speed. Therefore cosmic rays are generally low is mass. As a result, they can pass through the atoms in your body undisturbed. (Well mostly)
 
So how do cosmic rays cause computer crashes?
Answer: Computers processors are based on logic gates which manage the flow of electrons on the processor. When a cosmic ray hits the processor a surge or peak of energy is releases in the form of electrons which can result in the processor providing inaccurate results. (Hence it crashes).
 
So with the details out of the way I can get on to explaining what the Intel researcher was planning to in order to resolve this problem. Basically, his view on cosmic crashes was that it’s going to be almost impossible to stop them from happening,  insulating the processor with cosmic ray impenetrable materials is going to be very hard, very large and expensive. So, instead he proposed that what we should do is build detectors which can identify the surge of electrons associated with a cosmic ray and then instruct the processor to rerun the previous calculation that may have been affected.
 
 I must say... I like his thinking.
Comments (0)

LINQ to Reflection Part 3: Updating Fields
By David Hanson on Mon, 28 Apr 2008 13:30:07 GMT
In part 2 of this LINQ 2 Reflection series I took you through how we go about querying fields that may existing within an object graph. Before we proceed, it’s important to remember that a call to object.Field<T> will return an instance of type Linq.Reflection.Field. As part 2 focused purely the reading fields it’s about time we take a look at how we can go about updating them. If we look at the intellisense that Visual Studio provides for the Field<T> class we can see that this class has an Update<T> method. Shown below.
 
 
Firstly, as the Update<T> method is contextual, there is no requirement to pass the name of the field we wish to update as this can be inferred from its parent. Secondly, As the Field<T> returns a generic class of type T it also allows us to infer the Type of value we wish to update. Below is a simple update statement on a person entity.
 
person
    .Field<string>("_firstName").Update("James")
    .Field<string>("_lastName").Update("Brown")
    .Field<DateTime>("_dateOfBirth").Update(DOB);
 
The Update<T> method of the Field<T> class returns an instance of the parent object we are currently working with. Internally the Field<T> class passes the parent context down our chained methods. Therefore we have the ability to move up the object graph if so desired. In this situation, where we are updating 1 of many fields on the parent context, its important that the return value from Update<T> is that of the parent object.
 

As that’s pretty much it for updating fields using LINQ to Reflection. You can call the Update<T> on and Field<T> or Property<T> accessor. As this point in our series you have the information you need to drill down any object reading and writing property/field values to suit your tests scenarios.  

In part 4 we will start looking at how we can leverage the power of these extensions methods by showing how we can mock internal objects without breaking the rules of encapsulation.

Comments (0)

LINQ to Reflection Part 2: Reading Fields
By David Hanson on Fri, 25 Apr 2008 11:34:23 GMT
In part 1 of my LINQ to Reflection series I outlined some of the key drivers behind me creating a set of extension methods that can be used to query any CLR type. I also outlined that I am looking to extend this further with support for reading/writing of data, mocking, invocation, interception and other useful behaviours.  This post is purely focused on the reading of field data using the LINQ to Reflection extension methods.  
 
Before we get into the details of how we query data, we first need to create some tests data that will be used for each sample. Below is a method that is used to build object graph that is comprised simple and complex types with multiple child objects.  Note: We are already starting to use our LINQ to Reflection methods in order to create tests data.
 
        ///<summary>
        /// Sets up an object graph for our different test scenarios.
        ///</summary>
        public static Person GetTestData()
        {
            Person person = new Person();
            return FillPerson(person,3, 4);
        }
 
        ///<summary>
        /// Fills the person with test data.
        ///</summary>
        ///<param name="person">The person.</param>
        ///<param name="levelsDeep">
Comments (1) More...

WPF: Could not create an instance of type '{0}'
By David Hanson on Fri, 25 Apr 2008 09:10:57 GMT

If you get this error in your designer when working with XAML in Visual Studio 2008...make sure you dont have any visual elements that inherit from an abstract class.  May seem obvious but can be easily missed.

Could not create an instance of type '{0}'

Comments (6)

The rise and fall of social networks
By David Hanson on Wed, 23 Apr 2008 19:47:05 GMT

It seems every six months a new social network is on the scene. If I was to guess who currently reigns supreme I would imagine facebook is likely to be in there. Google trends provides us with some insights into this question.

facebook, myspace & bebo

I will run this graph in a year and see how its changed. Until then make your own minds up.

Comments (0)

Linq to Reflection: Part 1
By David Hanson on Wed, 23 Apr 2008 09:25:08 GMT

Firstly.... before you read this, I would really like feedback on this series of posts and the ideas it outlines. I wanted to get that request made on the first line as apparently most humans skip the next paragraph when searching for info. So with that out of the way I will outline what this post is really about.

 
These posts are the result of a bit of a mishmash of ideas that I have been thinking about of late. The project I am currently working is fully agile, therefore test driven development plays a key role in the day to day work a developer encounters. We perform integration testing, interaction testing, unit testing & business testing as well as a few other kinds of testing during the course of writing functionality. The project has also recently migrated.NET 3.5 and a result we have started to take advantage of some of the languages features such as LINQ.
 
When I first heard of LINQ I must admit I was sceptical. I am one of those developers who likes to have a thorough understanding of the architecture prior to implementing it my code base. (Remember VB web classes anyone).  I picked up the Pro-LINQ book from Apress a while back and spent a weekend reading from cover to cover. So before I continue I will clarify my position on these technologies.
 
LINQ to Objects is superb.
LINQ to XML is just as good.
LINQ to SQL is good but not there yet! (Release 3 Perhaps).
LINQ to Entities (Barge pole and touch come to mind).
 
So with  that said I will try and move onto the focus of these posts. LINQ to Objects has been implemented using .NET 3.5 extension methods. Extension methods allow you to implement instance type methods on existing classes. Even if these classes are sealed or you do not have the source code so you can extend them. So given this new feature it got me thinking about what possible uses there are for extension methods.  LINQ uses them primarily on types of IEnumerable in order to implement query expressions, but I wanted to see if I could use them in a more generic fashion on any type of object.
 
As I felt I had a solution looking for a problem, I decided to bide my time and wait for the problem to present itself. A couple of weeks ago it did!! As said, we are working on a project which has adopted TDD. One of the issue I find with TDD is that I kept feeling I had to break encapsulation principles in order to increase testability. An internal field on a class would need to be set for a specific test condition to pass or an object deep down in my object graph would need to be configured or mocked in order to allow testing. IOC & dependency injection admittedly can help in this area but are not always the simplest of solutions.  So end game is that I want to avoid this wherever possible.
 
Currently, In order to solve some of these problems, our project has a number of utility classes for accessing private members on a reference types. This only goes so far and can be cumbersome to use. What I would ideally like in my tool kit is the ability to seamlessly drill down an object graph using a familiar syntax. More than that, I want to be able to instantly convert those fields or properties to mock objects prior to running my tests.  I want to be able to swap ...
Comments (1) More...

WPF: How to stretch columns in a ListView
By David Hanson on Sun, 13 Apr 2008 21:21:11 GMT
The ListView control in WPF is a powerful option when trying to present tabular data to users. It supports many of the common behaviours found in grid controls as well as the full WFP templating architecture we have all come to love. Below is a simple of example of a ListView which has been bound to a collection of strings. The example uses a template GridVewColumn and a 3 standard GridViewColumn’s to display the data.
 

And here is the associated XAML.
 
<Window x:Class="WPFSamples.ListViewDemo"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:s="clr-namespace:System;assembly=mscorlib"
    xmlns:Extensions="clr-namespace:Demo.Extension.Properties"
    Title="ListViewDemo" Height="353" Width="714">
    <Grid>
        <Grid.Resources>
           
            <x:
Comments (11) More...

Silverlight Control Skins
By David Hanson on Tue, 08 Apr 2008 19:09:40 GMT

Corrina Barber has a great post about her new Silverlight controls skins which provide a pencil drawn visual style for the common controls.

Click to see live demo

Its great to see these kinda resources being available online. It showns the power of the WPF templating model and makes us think differently about how user interfaces can be delivered. V cool.

Comments (0)

New look and feel for OnTheBlog.net
By David Hanson on Tue, 08 Apr 2008 10:56:54 GMT

You may have noticed that the look of my site has changed a little. I kept getting comments that it was a little too white so i decided to jig it around a bit. As DNN implements a superb skinning architecture it was very easy to do.

If you would like to see what the site used to look like you can click here.

Old skin

 

Comments (0)

Silverlight and Flex trends
By David Hanson on Sat, 05 Apr 2008 16:19:48 GMT

I love playing with Google trends, today as a thought I decided to pop in a the following comparison for Flex and Silverlight. Not much between them at the moment it seems.

Comments (0)

C# Binary Search
By David Hanson on Mon, 07 Apr 2008 12:50:37 GMT

A binary search is an algorithm is able to find a specific value within a sorted array by making increasingly acurate guesses based on a comparision result. I was discussing this with a friend at work the other day and thought I would put one together in C# for illustrative purposes. 

First we need to create the array with random data and then sort this array. I decided that using guids would provide a good level of random data for our test. I therefore create a million guids in my array then sort it. This is shown below.

        ///
        /// Mains the specified args.
        ///
        /// The args.
        static void Main(string[] args)
        {
 
            //Setup random data.
            List<String> RandomItems = new List<string>();
            for (int i = 0; i < 1000000; i++){RandomItems.Add(Guid.NewGuid().ToString());}
            //Get search item and sort.
            string searchFor = RandomItems[345];
            RandomItems.Sort();
            Console.WriteLine("Press enter to run test" ...
Comments (3) More...

Macbook Pro and Vista
By David Hanson on Wed, 02 Apr 2008 12:51:45 GMT

I recently updated my laptop to a Macbook Pro 2.6Ghz Intel Core 2 Duo with 4gb of ram with the 200gb 7200rpm disk. I have created a windows partition on the machine and installed vista, Visual Studio 2008, SQL Server 2005, Office 2007 etc etc.

Anyways, Just wanted to express that this machine is blisteringly fast! My performance score is shown below.

 

Comments (0)

Decompiling Silverlight Apps
By David Hanson on Sat, 29 Mar 2008 20:48:08 GMT

Did you know you can decompile Silverlight apps? As with ever other .NET app, if you have the assemblies you can pretty much load them into reflector and view the source.

So when it comes to silverlight how do you get the assemblies in the first place? Well it turns out when you develop your app all the assemblies are packages into a XAP file which is then downloaded to the client.

An XAP is actually just a zip file with a different extension. Therefore, all you need to do is the following.

1.) Locate the XAP file on a web page or file system by looking at the source.

2.) Place into the browser and download the XAP package.

3.) Once downloaded, change the XAP extension to .ZIP

4.) Extract the package using whichever tool you like. I use WINRAR.

5.) Locate the assemblies in reflector and view the source.

Comments (0)

Linq Gotcha: Deferred Queries
By David Hanson on Sat, 05 Apr 2008 16:05:02 GMT
 
In Linq there are two kinds of queries you can execute on objects. Deferred and Non-Deferred. As expected, non-deferred queries will be executed immediately, deferred queries on the other hand will not be executed until iterate over the collection.
  
With that in mind take the following query
 
            string[] servers = { "Server 1", "Server 2", "Dave" };
            IEnumerable<string> results = servers.Where(server => Char.IsDigit(server[7]));
 
In this query we want to bring back the first two elements in our array which have a number at the 7th index, therefore we would get two results returned.  However, although this code compiles, we have actually created a situation whereby a System.IndexOutOfRange exception will be thrown whenever this query is executed, this is because the  server name Dave is only 4 chars long.   This should be easy to find if we start using our results collection directly below our query but this may not always be the case. We may do the following.
 
 
            string[] servers = { "Server 1", "Server 2", "Dave" };
            IEnumerable<string> results = servers.Where(server => Char.IsDigit(server[7]));
                                ConnectToServer(results);            
 
Our ConnectToServer method
 
                public void ConnectToServer(IEnumerable<String> servers)
      {
            if(servers.Count > 0)
             & ...
Comments (0) More...

Multiple Browser Compatibility
By David Hanson on Mon, 24 Mar 2008 17:40:49 GMT

Rockford has an interesting post about a website called http://browsershots.org. The idea is, you submit a url and they will check how your website renders in 45+ browsers on multiple operating systems and provide screenshots for you to download. They also do some cool javascript testing as well.

Below is an a screenshot of the initial results page for the home page of my site.

And here is what my site looks like in Opera running on linux. V.cool.

 

Comments (0)

Print  
Tweets Minimize
Twitter / LordHanson
  1. LordHanson: Flash on iPad....nice. http://www.tipb.com/2010/07/04/frash-android-flash-ported-ipad/

    Published Sun, 04 Jul 2010 22:07:55 +0000 by
  2. LordHanson: Anyone noticed that when typing on your iPhone it sounds like your holding a gieger counter?

    Published Sun, 04 Jul 2010 22:05:28 +0000 by
  3. LordHanson: Missing wacko's music... What's happened to the album he was working on before he died?

    Published Fri, 25 Jun 2010 23:01:45 +0000 by
  4. LordHanson: New version of Connectify cannot recognise my active Internet connection! Had to roll back to previous version! #fail

    Published Fri, 25 Jun 2010 22:54:54 +0000 by
  5. LordHanson: vuvuzela blowing spoils the world cup! Fact!

    Published Mon, 14 Jun 2010 05:08:43 +0000 by
  6. LordHanson: About http://www.theaustralian.com.au/business/news/us-competition-regulators-to-investigate-apple/story-e6frg90x-1225878779986

    Published Mon, 14 Jun 2010 00:04:45 +0000 by
  7. LordHanson: In the camper van and a storm is coming.....How exciting.

    Published Sun, 25 Apr 2010 04:39:48 +0000 by
  8. LordHanson: My vaio p is doing well while travelling. 3g Internet, HD movies, digital tv, photo editing, wifi router for iPods and much more. Love it

    Published Wed, 10 Mar 2010 10:29:19 +0000 by
  9. LordHanson: Ok so I need to stay techie while away from a computer for a year. Anyone got any ideas.

    Published Mon, 22 Feb 2010 12:31:09 +0000 by
  10. LordHanson: Sitting in YHA Glebe Sydney waiting for the movie night to start

    Published Thu, 18 Feb 2010 08:13:10 +0000 by
  11. LordHanson: I finished work today in prep for travelling. I must admit as i left the office i felt a little emotional. Sign of a good job with great ...

    Published Tue, 26 Jan 2010 17:48:49 +0000 by
  12. LordHanson: Lots of sick sounding people creeping onto the trains today. Stay away stay away!

    Published Fri, 22 Jan 2010 08:14:36 +0000 by
  13. LordHanson: LMAO RT @colmbrophy: so have you seen who owns http://wwwbing.com ? it's not microsoft

    Published Tue, 19 Jan 2010 17:35:43 +0000 by
  14. LordHanson: RT @TeemuHyn: RT @eldarmurtazin: Hate Windows Mobile 7. No apps from previous versions of WM working here. Not compatible at all.

    Published Sun, 17 Jan 2010 19:01:29 +0000 by
  15. LordHanson: The girlfriend has gone all science on me.... She has her head in books about quasars!

    Published Sat, 16 Jan 2010 16:38:58 +0000 by
  16. LordHanson: New blog post: Invoking generic methods with Expression.Call http://bit.ly/5g99Ih

    Published Sat, 16 Jan 2010 16:34:00 +0000 by
  17. LordHanson: Found a nice way to invoke generic methods using expression trees and importantly avoiding Type.Getmethods() which you normally have to do!

    Published Fri, 15 Jan 2010 18:55:38 +0000 by
  18. LordHanson: Tried a dummy run of packing my backpack last night. Just managed to get it all in. The sleeping bag takes half the space. Not good.

    Published Fri, 15 Jan 2010 08:28:47 +0000 by
  19. LordHanson: Why do we get headaches for no apparent reason?

    Published Tue, 12 Jan 2010 15:28:29 +0000 by
  20. LordHanson: @swhelband beer time my friend

    Published Sun, 10 Jan 2010 21:49:44 +0000 by
Print  
Archive Minimize
Print  
Contact me Minimize
Print  
Microsoft Certs Minimize







Print  
Silverlight News Minimize
Silverlight - Google News
  1. Top 10 Things I Wish I Knew Before I Started My Silverlight 4 Project - Redmond Developer News

    Published Thu, 29 Jul 2010 23:21:01 GMT+00:00 by
  2. Microsoft's Flash challenger Silverlight hits Symbian - Register

    Published Tue, 06 Jul 2010 18:54:39 GMT+00:00 by
  3. Windows Phone 7 misses big-business support tools - Register

    Published Mon, 26 Jul 2010 20:32:23 GMT+00:00 by
  4. Neustar Reports Q2 Results, Stock Repurchase - TMCnet

    Published Fri, 30 Jul 2010 13:13:57 GMT+00:00 by
  5. Intertainment begins commercial rollout of Ad Taffy - PR Newswire (press release)

    Published Fri, 30 Jul 2010 14:19:22 GMT+00:00 by
  6. Download Microsoft Expression Studio Ultimate 4.0.20525.0 Free Trial / Full ... - Soft Sailor (blog)

    Published Fri, 30 Jul 2010 08:50:54 GMT+00:00 by
  7. Managing change in the application portfolio - Register

    Published Thu, 29 Jul 2010 09:36:57 GMT+00:00 by
  8. Queen Victoria in Liverpool panoramic picture - Liverpool Echo

    Published Mon, 26 Jul 2010 11:56:30 GMT+00:00 by
  9. AEBN's Silverlight Player Gains Traction with Users - AVN News (press release)

    Published Tue, 27 Jul 2010 20:28:37 GMT+00:00 by
  10. Written by David Conrad - iProgrammer

    Published Tue, 27 Jul 2010 12:39:37 GMT+00:00 by
Print